SQL xml: get xml values into CSV?
-
Hi In SQL 2005, I am trying to get a csv strin like "1212,1122,1123,1124" out of following xml. 1212 1122 1123 1124 Please advise how it can be done? Thanks Pankaj
-
Hi In SQL 2005, I am trying to get a csv strin like "1212,1122,1123,1124" out of following xml. 1212 1122 1123 1124 Please advise how it can be done? Thanks Pankaj
The data you posted isn't in xml format so it's quite hard to say what the correct way would be. But let's suppose you have something like in the following example, then your query could be
declare @testdata xml
set @testdata =
'<Root>
<element>1212</element>
<element>1122</element>
<element>1123</element>
<element>1124</element>
</Root>'
SELECT @testdata.query('for $e in /Root/element return concat(string($e),'', '')')The need to optimize rises from a bad design.My articles[^]
-
The data you posted isn't in xml format so it's quite hard to say what the correct way would be. But let's suppose you have something like in the following example, then your query could be
declare @testdata xml
set @testdata =
'<Root>
<element>1212</element>
<element>1122</element>
<element>1123</element>
<element>1124</element>
</Root>'
SELECT @testdata.query('for $e in /Root/element return concat(string($e),'', '')')The need to optimize rises from a bad design.My articles[^]
Thanks. With little tweak I can get desired result.
-
Thanks. With little tweak I can get desired result.