sql - Union in xml select query -
i selecting data table xml. used xml path , have succeeded. in xml need add 1 section named return dummy used later. have select query return section xml. need union both these select queries single xml.
my code
select cast(idno varchar(8)) [idno] ,cast(code varchar(4)) [code] ,cast(amt varchar(18)) [amt] tbl1 xml path('item'), root('table1'), type select '' iname ,'' unq_id ,'' status xml path('it_return')
please advise me.
edit: expected output is
<table1> <item> <idno>0283883</idno> <code>abc</code> <amt>20</amt> </item> <item> <idno>0374747</idno> <code>dhf</code> <amt>10</amt> </item> </table1> <it_return> <iname></iname> <unq_id></unq_id> <status></status> </it_return>
the following trick you:
declare @tbl1 table ( idno varchar(8), code varchar(4), amt varchar(18) ) insert @tbl1 values ( '0283883', 'abc', '20' ), ( '0374747', 'dhf', '10' ) select ( select cast(idno varchar(8)) [idno], cast(code varchar(4)) [code], cast(amt varchar(18)) [amt] @tbl1 xml path('item'), root('table1'), type ), ( select '' iname ,'' unq_id ,'' status xml path('it_return'), type ) xml path('')
Comments
Post a Comment