开发者

How to convert a list of items in SQL xml variable to a table

I have a very simple xml that I pass to a sql sproc as a parameter. But for simplicity I pres开发者_JS百科ent it in declare.

declare @a xml;
set @a='<items>
  <item>1</item>
  <item>3</item>
  <item>5</item>
  <item>7</item>
</items>';

How do I convert this list to a table so I could make joins, etc. Basicly, How do I retrieve a table in the following form:

item
----
1
3
5
7

Thank you!


You could use the nodes function:

select  items.item.value('.','int')
from    @a.nodes('items/item') as items(item)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜