开发者

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

开发者 https://www.devze.com 2023-03-15 11:30 出处:网络
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.

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

精彩评论

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