SELECT
tw_Symbol
,TowarSkladnikiKompletu = (
STUFF (
(
SELECT
'|' + (SELECT tw_Symbol FROM tw__Towar WHERE tw_Id = KPL.kpl_IdSkladnik) + 'x' + CAST(KPL.kpl_Liczba AS VARCHAR(MAX))
FROM
tw_Komplet KPL
JOIN tw__Towar on kpl_IdKomplet = tw_Id
WHERE
tw_Id = TOWAR.tw_Id FOR XML PATH ('')
),
1,
1,
''
)
)
FROM tw__Towar TOWAR
WHERE tw_Rodzaj = 8
ORDER by tw_Symbol