0
<a>
<b>
<c>
<customer>Miller</customer>
<d id="21">Bike</d>
<d id="22">Helmete</d>
</c>
</b>
</a>
내가 다음 쿼리를 시도 다음과 같은 출력을 원하는 XML의 PATH T-SQL의 쿼리에 대한 단일 노드에서 쿼리 및 하위 쿼리 결과를 결합하는 방법 (다른 stackexchange 페이지에서 도난 수정)
--Table for demo
declare @OrderTbl table (id int, customer nvarchar(100))
declare @OrderDetail table (ID int, fk_Order int,Item nvarchar(100))
--Load some data
insert into @OrderTbl select 1, 'Miller'
insert into @OrderDetail select 21 ,1,'Bike'
union all select 22 ,1,'Helmete'
union all select 23 ,2,'Bike'
union all select 24 ,2,'Helmete'
select
a.customer as "c/customer"
, ( select b.ID as "@id"
, b.Item AS "data()"
from @OrderDetail b
where a.id = b.fk_Order
for xml path('d'),root('c'),type
)
from @OrderTbl a
for xml path('b'),root('a')
그러나 그것은 나에게 준 내가 영으로 지금은 그것을 kludged
<a>
<b>
<c>
<customer>Miller</customer>
</c>
<c>
<d id="21">Bike</d>
<d id="22">Helmete</d>
</c>
</b>
</a>
다음VARCHAR 할 수있는 쿼리 결과를 캐스팅하고
""
으로
"</c><c>"
를 교체하지만 달랐어 요, 몹시 우아하다. 누구든지 더 좋은 방법을 제안 할 수 있습니까?
감사합니다. –