sql server - Generate XML from Query with a certain XSD definition? -
i have following query
select a,b,c,d,e,f,g,h view1 = '....'
and want generate following xml. possible use sql server for xml
it? or there other approach can implemented in sql server?
<root> <a>....</a> <!-- appear once --> <b id="1"> <type c="..." d="..."> <subtype> <element e="..." f="...."> <g>...</g> <h>...</h> </element> ..... </subtype> .... <type> ..... </b> <b>.....
yes for xml path
can used desired result
declare @test table ( int, b int, c int, d int, e int, f int, g int ) insert @test values (1,2,3,4,5,6,7) insert @test values (1,3,4,4,5,6,7) select (select top 1 @test a=1 ) 'a/text()', ( select b '@id', (select c '@c', d '@d', e 'subtype/element/@e', f 'subtype/element/@f', g 'subtype/element/g/text()', f 'subtype/element/f/text()' xml path('type'), type ) @test =1 xml path('b'), type ) xml path(''), root('root')
Comments
Post a Comment