如何在SQL Server中读取XML值?

时间:2021-07-25 17:03:28

I have a list of strings as:

我有一个字符串列表:

    List<string> list = new List<string>();
    list.Add("912-123898493");
    list.Add("021-36574864");
    list.Add("021-36513264");

I want to convert it in XML and then send it as a parameter to Stored procedure, so that this could be read.

我想要将它转换成XML,然后将它作为参数发送到存储过程,以便读取它。

How to read this XML in sql server so that each and every string can be placed in different cell? Please help!!

如何在sql server中读取这个XML,以便每个字符串都可以放在不同的单元中?请帮助! !

1 个解决方案

#1


4  

It depends of what structure your xml will have. Here's example of how you can read elements xml:

这取决于xml的结构。下面是如何读取xml元素的示例:

declare @Data xml

select @Data = '
<root>
    <value>912-123898493</value>
    <value>021-36574864</value>
    <value>021-36513264</value>
</root>'

select T.C.value('data(.)', 'nvarchar(128)') as [Data]
from @Data.nodes('/root/value') as T(C)

#1


4  

It depends of what structure your xml will have. Here's example of how you can read elements xml:

这取决于xml的结构。下面是如何读取xml元素的示例:

declare @Data xml

select @Data = '
<root>
    <value>912-123898493</value>
    <value>021-36574864</value>
    <value>021-36513264</value>
</root>'

select T.C.value('data(.)', 'nvarchar(128)') as [Data]
from @Data.nodes('/root/value') as T(C)