I have a simple table in SQL Server 2005, I want to convert it to XML (using the FOR XML clause). I am having trouble getting my XML to look like the required output.
I tried to browse various tutorials on the Internet, but I'm afraid. Can anyone help?
In a table that looks like this
TYPE,GROUP,VALUE
Books,Hardback,56
Books,Softcover,34
CDs,Singles,45
CDS,Multis,78
I need an output style:
<data>
<variable name="TYPE">
<row>
<column>GROUP</column>
<column>VALUE</column>
</row>
<row>
<column>GROUP</column>
<column>VALUE</column>
</row>
</variable>
<variable name="TYPE">
<row>
<column>GROUP</column>
<column>VALUE</column>
</row>
<row>
<column>GROUP</column>
<column>VALUE</column>
</row>
</variable>
</data>
Edit:
As far as I can tell, I need a few values. I am creating XML for use with Xcelsius ( Linking XML and Xcelsius ), so I have no control over XML formatting. I can generate XML using ASP according to the related tutorial, but I was hoping to get it directly from SQL Server.
2:
- ... . SQL, :
select
"type" as '@name',
"group" as 'row/column',
null as 'row/tmp',
"value" as 'row/column'
from tableName
for xml path('variable'), root('data')
, . null/tmp ; . <variable name="TYPE"> , .