Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8556

Re: SQL Query for XML (row/column format)

$
0
0

For the ones whohavethe same problem, here is aSQLscripttothe desiredXMLformat(variable,row/column)


USE <DATABASENAME>

;With CTE

AS

(

SELECT [ColumnA]

,[ColumnB]

,[ColumnC]

FROM TABEL

)

 

select [ColumnA] AS [@name],

(select [ColumnB] as [column],

null as tmp,

ColumnC as [column],

from CTE

where [ColumnA] = t.[ColumnA]

for xml path('row'),type) as [*]

from (select distinct [ColumnA] from CTE)t

for xml path('variable'),root('data')

 

In this script the variable is named by the value of ColumnA.

 

 

Regards,

 

 

Bart


Viewing all articles
Browse latest Browse all 8556

Trending Articles