sql - Add an attribute to the root node -
please see ddl below:
create table #dataset1 (id int not null identity,firstname varchar(30),surname varchar(30), primary key (id)) insert #dataset1 (firstname,surname) values ('mark','williams')
and sql below:
select firstname,surname #dataset1 xml path('dataset1')
which returns:
<dataset1> <firstname>mark</firstname> <surname>williams</surname> </dataset1>
how can sql return:
<dataset1 urn='1'> <firstname>mark</firstname> <surname>williams</surname> </dataset1>
urn=1 harcoded xml i.e. not generated database.
try this
select id [@urn] ,firstname ,surname #dataset1 xml path ('dataset1')
result
<dataset1 urn="1"> <firstname>mark</firstname> <surname>williams</surname> </dataset1>
Comments
Post a Comment