I have a value in my MS SQL table column called "XDATA" like this:
<root><KV><Key>1</Key><Value>A</Value></KV>
<KV><Key>2</Key><Value>B</Value></KV>
<KV><Key>3</Key><Value>C</Value></KV></root>
I want to be able to get the value of the row back like this:
KEY, VALUE
1,A
2,B
3,C
So far I have written this:
DECLARE @a1 xml
declare @x xml;
set @x = '<root><KV><Key>1</Key><Value>A</Value></KV>
<KV><Key>2</Key><Value>B</Value></KV>
<KV><Key>3</Key><Value>C</Value></KV></root>';
SELECT @a1 = @x.query('(/root/KV/Key/text())')
select @a1
But I am getting 123 back. Not three rows with two columns. How do I get three rows back, each row with two columns:
KEY, VALUE
1,A
2,B
3,C
Thanks