Microsoft SQL Server xml data
Posted
by cf_PhillipSenn
on Stack Overflow
See other posts from Stack Overflow
or by cf_PhillipSenn
Published on 2010-04-21T16:54:49Z
Indexed on
2010/04/21
17:13 UTC
Read the original article
Hit count: 96
sql-server
This site has a technique to pass xml data around in Microsoft SQL Server:
DECLARE @productIds xml
SET @productIds ='<Products><id>3</id><id>6</id><id>15</id></Products>'
SELECT
ParamValues.ID.value('.','VARCHAR(20)')
FROM @productIds.nodes('/Products/id') as ParamValues(ID)
But what is the syntax if I add another field? The following does NOT work:
DECLARE @productIds xml
SET @productIds ='<Products><id>3</id><descr>Three</descr><id>6</id><descr>six</descr><id>15</id><descr>Fifteen</descr></Products>'
SELECT
ParamValues.ID.value('.','VARCHAR(20)')
,ParamValues.descr.value('.','VARCHAR(20)')
FROM @productIds.nodes('/Products/id') as ParamValues(ID)
Note: Maybe I've constructed my xml wrong.
© Stack Overflow or respective owner