XML To Sql Server -


i trying import xml file sql server no success yet.
xml file structured this:

<users xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">     <user>     <partitionkey>be-by</partitionkey>   </user> </users>   

i using following code:

   select      xmldata.value('(partitionkey)[1]', 'nchar(10)') 'partition_key'        (select cast(x xml)      openrowset(         bulk 'c:\program files\microsoft sql server\mssql10.mssqlserver\mssql\backup\skillagexml\userstest1111.xml',         single_blob         )          t(x)     )  t(x) cross apply      x.nodes('/users/user') x(xmldata); 

however, don't see value after done processing file. there missing?

this works charm me:

select      xusers.value('(partitionkey)[1]', 'nchar(10)') 'partition_key'        (select          bulkxml = cast(bulkcolumn xml)               openrowset(bulk 'c:\program files\microsoft sql server\mssql10.mssqlserver\mssql\backup\skillagexml\userstest1111.xml', single_blob) bx      ) t cross apply      bulkxml.nodes('/users/user') xtbl(xusers);and returns:  partition_key be-by      

i think you're approach of using as t(x) alias twice causing confusion - try use more meaningful , not same alias both things.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -