Talha Majid
Talha Majid

Reputation: 127

How to read XML values in SQL Server

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.

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

Upvotes: 3

Views: 2589

Answers (1)

roman
roman

Reputation: 117380

It depends of what structure your xml will have. Here's example of how you can read elements 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)

Upvotes: 5

Related Questions