Hi
I am having difficulty understanding how the FOR XML EXPLICIT WORKS.
Here is my sample code:
create table #t1 (f1 char(3))
insert into #t1 values ('XXX')
insert into #t1 values ('YYY')
create table #t2 (f2 char(3))
insert into #t2 values ('AAA')
select 1 Tag, NULL Parent,
f2 [LogFiles!1!Path!element],
null [Files!2!File!element]
from #t2
union
select 2 Tag, 1 Parent,
f2 ,
f1
from #t2
inner join #t1 on 1=1
order by [LogFiles!1!Path!element],[Files!2!File!element]
for xml explicit
drop table #t2
drop table #t1
This produces:
<LogFiles><Path>AAA</Path><Files><File>XXX</File></Files><Files><File>YYY</File></Files></LogFiles>
What I would like is:
<LogFiles><Path>AAA</Path><Files><File>XXX</File><File>YYY</File></Files></LogFiles>
i.e. not having the extra "files" tag.
HELP! What am I doing wrong?
Thanks
Moptop
I am having difficulty understanding how the FOR XML EXPLICIT WORKS.
Here is my sample code:
create table #t1 (f1 char(3))
insert into #t1 values ('XXX')
insert into #t1 values ('YYY')
create table #t2 (f2 char(3))
insert into #t2 values ('AAA')
select 1 Tag, NULL Parent,
f2 [LogFiles!1!Path!element],
null [Files!2!File!element]
from #t2
union
select 2 Tag, 1 Parent,
f2 ,
f1
from #t2
inner join #t1 on 1=1
order by [LogFiles!1!Path!element],[Files!2!File!element]
for xml explicit
drop table #t2
drop table #t1
This produces:
<LogFiles><Path>AAA</Path><Files><File>XXX</File></Files><Files><File>YYY</File></Files></LogFiles>
What I would like is:
<LogFiles><Path>AAA</Path><Files><File>XXX</File><File>YYY</File></Files></LogFiles>
i.e. not having the extra "files" tag.
HELP! What am I doing wrong?
Thanks
Moptop