Попробуйте, не проверено мною, поэтому там может быть любое количество опечаток.
select *,
(select *
from EDI834_5010_2300_DTPLoop VLine
where Line.REF02_MemberSupplementalIdentifier = VLine.Id_REF02__SubscriberIdentifier and Header.BGN02__TransactionSetIdentifierCode = VLine.Id_BGN02__TransactionSetIdentifierCode
for xml auto, elements, type),
(select *
from EDI834_5010_2300_LUILoop LUI
where LUI.Id_BGN02__TransactionSetIdentifierCode=Header.BGN02__TransactionSetIdentifierCode and LUI.Id_REF02__SubscriberIdentifier=Line.REF02_MemberSupplementalIdentifier
for xml auto, elements, type)
from EDI834_5010_Header Header
join EDI834_5010_2000 Line
on Header.BGN02__TransactionSetIdentifierCode = Line.Id_BGN02__TransactionSetIdentifierCode
for xml auto, elements
Используется для проверки работоспособности подзапросов и их работы.
declare @t1 table (id int)
declare @t2 table (id int)
declare @t3 table (id int)
insert into @t1 values (1),(2)
insert into @t2 values (1),(2)
insert into @t3 values (1),(2)
select *,
(select *
from @t2 as t2
where t1.id = t2.id
for xml auto, elements, type),
(select *
from @t3 as t3
where t1.id = t3.id
for xml auto, elements, type)
from @t1 as t1
for xml auto, elements
Результат:
<t1>
<id>1</id>
<t2>
<id>1</id>
</t2>
<t3>
<id>1</id>
</t3>
</t1>
<t1>
<id>2</id>
<t2>
<id>2</id>
</t2>
<t3>
<id>2</id>
</t3>
</t1>