sql server 2005 - select xml filename from database -


i have sql script loads filenames of xml's in database (tmp1).

the list looks this:

20130918_0932_zsk40-2.xml 20130918_1032_zsk70.xml 20130921_0532_zsk40-2.xml 

in script want load each xml file can import in database.

what need select first file name in tmp1 load it.

the part of script load file this:

 select cast(xmlcontent xml)     openrowset(          bulk 'c:\20130921_0532_zsk40-2.xml',          single_blob) t(xmlcontent)          ) t(xmlcontent) 

what should like?

thanks in advance,

if object_id('tempdb..#tmptable') not null  drop table #tmptable  select machine = xmlcontent.value('(/recordeddata/machine)[1]', 'varchar(50)'),  recordingdate = xmlcontent.value('(/recordeddata/date)[1]', 'varchar(50)'),  recordingtime = xmlcontent.value('(/recordeddata/hour)[1]', 'varchar(50)'),  variablename = xvar.value('(name)[1]', 'varchar(50)'),  variablevalue = xvar.value('(value)[1]', 'varchar(50)') #tmptable (  select cast(xmlcontent xml) openrowset(  bulk 'c:\xml_path_here.xml',  single_blob) t(xmlcontent)  ) t(xmlcontent) cross apply  xmlcontent.nodes('/recordeddata/collecteddata/variable') xtbl(xvar)  declare @cols nvarchar(max),  @query nvarchar(max); set @cols = stuff((select distinct ',' + quotename(c.variablename)   #tmptable c  xml path(''), type  ).value('.', 'nvarchar(max)')   ,1,1,'') set @query = 'select machine, recordingdate, recordingtime, ' + @cols + '   (  select machine  , recordingdate  , recordingtime  , variablename  , variablevalue  #tmptable  ) x  pivot   (  max(variablevalue)  variablename in (' + @cols + ')  ) p '   execute(@query) --select * #tmptable drop table #tmptable 


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -