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

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -