XYZID = 1
の場合 .
select stuff((select '#'+col2+'-'+col3+'-'+col4 from TableB where XYZID = 1 order by seq for xml path(''), type).value('.', 'nvarchar(max)'), 1, 1, '')
プレ>TableA のすべての行:
select stuff((select '#'+col2+'-'+col3+'-'+col4 from TableB as B where A.XYZID = B.XYZID order by seq for xml path(''), type).value('.', 'nvarchar(max)'), 1, 1, '') from TableA as A
プレ>