SQL XML - Return result set
I have the following SQL Query:
declare @x xml
set @x = '<IDs><ID>1</ID><ID>2</ID></IDs>'
SELECT @x.query('/IDs/ID') as ID
This returns the following result:
ID
--------------------
<ID>1&开发者_开发百科lt;/ID><ID>2</ID>
How can I instead get this to return:
ID
--
1
2
Use this code instead:
declare @x xml
set @x = '<IDs><ID>1</ID><ID>2</ID></IDs>'
SELECT ID.value('.', 'int') AS ID
FROM @x.nodes('/IDs/ID') as IDS(ID)
精彩评论