I have a SQL Server table with 2 XML columns in a table as shown here:
| Column A | Column B | Column C |
|---|---|---|
| Test1 | XML Value | XML Value1 |
| Test2 | XMLValue2 | XML Value3 |
XML values look like this:
<collection>
<object>
<fields>
<field>
<value>Savings account</value>
</field>
</fields>
</object>
<object>
<fields>
<field>
<value>Mortgage</value>
</field>
</fields>
</object>
</collection>
I want to display result as shown here:
| Column A | Column B | Column C |
|---|---|---|
| Test1 | Saving Accounts, Mortage | Saving Accounts, Mortage |
| Test2 | Saving Accounts, Mortage | Saving Accounts, Mortage |
I am trying to use below one, but it gives me result for only one column.
select t.N.value('value[1]','varchar(max)')
from @x.nodes('/collection/object/fields/field') as t(N)
OR
@x.query('/collection/object/fields/field/value[1]')
Can anyone help me solve this problem?