开发者

SQL XML - Return result set

开发者 https://www.devze.com 2023-02-03 05:06 出处:网络
I have the following SQL Query: declare @x xml set @x = \'<IDs><ID>1</ID><ID>2</ID></IDs>\'

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消