开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜