August 13, 2008 at 12:22 am
I have attached the sample xml code for reference. What i want to do is.
getting the values for each customer in below format
CustomerID|Name|City|ProjectID|Projectname
4HardwareshopWashington2Pegasus
4HardwareshopWashington8Typhon
i am able to get only customerid by using below query...
SELECTnref.value('(@CustomerID)[1]', 'int') AS CustomerID
FROM @xml.nodes('declare namespace E="http://www.w3org.com/CustomersSchema.xsd";/E:Customers') AS R(nref)
How can i get the above result.
Abhijit - http://abhijitmore.wordpress.com
August 13, 2008 at 3:35 am
select b.value('@id','int') as CustomerID,
b.value('./name[1]','varchar(20)') as Name,
b.value('./city[1]','varchar(20)') as City,
d.value('@id','int') as ProjectID,
d.value('./name[1]','varchar(20)') as Projectname
from @xml.nodes('/customers/customer') as a(b)
outer apply b.nodes('./projects/project') as c(d)
You'll need to resolve any namespace issues yourself
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537August 13, 2008 at 9:28 am
Thanks for your replu. I already resolved the problem like you have resolved, but i am getting the prob while using namespace
Abhijit - http://abhijitmore.wordpress.com
August 13, 2008 at 9:43 am
You'll need to post the XML with the namespace declarations
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply