Re: From varchar(max) to xml
- From: Peter Flynn <peter.nosp@xxxxxxxxxxxxx>
- Date: Sat, 24 Jun 2006 01:11:16 +0100
psychodad71 via SQLMonster.com wrote:
I have a table with 2 columns. Column a(varchar(max)) and column b(xml).
Column a contains the following data:
Col1;Col2
New York;USA
Rio;Brasil
Tokio;Japan
The first line contains the column header, the following the data.
The data should be transferred to column b with the following xml-structure:
<Col1>New York</Col1><Col2>USA</Col2>
<Col1>Rio</Col1><Col2>Brasil</Col2>
<Col1>Tokio</Col1><Col2>Japan</Col2>
The number of columns and the column names are various.
Any ideas?
If your database supports access to external scripting languages, dump
column a out and pass it through the following filter
awk -F\; 'BEGIN {ORS=""} {if(NR==1)n=split($0,gi);else{for(i=1;i<=NF;++i)print "<" gi[i] ">" $i "</" gi[i] ">";print "\n"}}'
and read the result into column b. The GNU awk processor for Windows can
be downloaded from http://gnuwin32.sourceforge.net/packages/gawk.htm
///Peter
.
- References:
- From varchar(max) to xml
- From: psychodad71 via SQLMonster.com
- From varchar(max) to xml
- Prev by Date: Re: From varchar(max) to xml
- Next by Date: Must be easy!!! How to get the both Element & Attribute value using OpenXML?
- Previous by thread: Re: From varchar(max) to xml
- Next by thread: Re: From varchar(max) to xml
- Index(es):