I am getting an XML parameter and now I want to get the data from it and use that data and call to another SP.
Right now I am trying to split up the input xml variable.
DECLARE @XML XML Set @XML = '<Products>
<product>
<id>3</id>
<name>Testar 3</name>
</product>
<product>
<id>6</id>
<name>Testar 6</name>
</product>
<product>
开发者_开发问答 <id>15</id>
<name>Testar 15</name>
</product>
</Products>'
SELECT CAST(A.B.query('./product/id/text()') AS VARCHAR(20)) as id, CAST(A.B.query('./product/name/text()') AS VARCHAR(50)) as name FROM @XML.nodes('/Products') as A(B)
But this only get me 1 row with 2 columns that look like this.
ID Name
3615 Testar 3Testar 6Testar 15
But what I want is this
ID Name
3 Testar 3
6 Testar 6
15 Testar 15
What do I need to change to achive that?
Thanks Magnus
select
P.value('id[1]', 'int') as ID,
P.value('name[1]', 'varchar(50)') as Name
from @XML.nodes('Products/product') as P(P)
精彩评论