sql server - Loop through columns having name T-SQL -
i have query:
select ac.*,cp.nomecampo fieldname optes op inner join artico art on art.id=op.idartico inner join sam.artcla3id13 ac on ac.idartico=art.id inner join campipers cp on cp.tabella = 'artcla3id3' op.id = 54782.000000
that returns this:
rivestimento | numtaglienti | raggio | diamscarico | fieldname | ______________________________________ nuda | 0 | 0 | 1 | diamscarico | nuda | 0 | 0 | 1 | diamscarico |
how can have this?
diamscarico | 1 raggio | 0 numtaglienti| 0 rivestimento| nuda
thanks!
you can put result of query xml variable , unpivot when querying xml.
declare @xml xml set @xml = ( -- query goes here select * yourtable -- here xml path(''), type ) select t.x.value('local-name(.)', 'sysname') columnnaame, t.x.value('./text()[1]', 'nvarchar(max)') value @xml.nodes('*') t(x)
Comments
Post a Comment