tsql - SQL SERVER FOR XML SYNTAX -
how can output follows using xml / sql query. not sure how can column values elements instead of tables' column names. using sql server 2005
i have table scema follows
create table parent ( pid int, pname varchar(20) ) create table child ( pid int, cid int, cname varchar(20) ) create table childvalue ( cid int, cvalue varchar(20) ) insert parent values (1, 'sales1') insert parent values (2, 'sales2') insert child values (1, 1, 'for01') insert child values (1, 2, 'for02') insert child values (2, 3, 'for03') insert child values (2, 4, 'for04') insert childvalue values (1, '250000') insert childvalue values (2, '400000') insert childvalue values (3, '500000') insert childvalue values (4, '800000')
the output looking follows
<sale1> <for01>250000</for01> <for02>400000</for02> </sale1> <sale2> <for03>500000</for03> <for04>800000</for04> </sale2>
can't understand why each node needs different tag -- won't fun query -- anyway, can explicitly (without xml).
do while loop on recordset incrementing min(pid), , select '<' + pname + '>'
, on. tricky format it's human-readable default xml files, still readable whatever web page, etc. have trying query it.
Comments
Post a Comment