SELECT OutBoundLinId,
STUFF(
(SELECT distinct ';' + RecCode FROM FI_ARReceivableSheets t
left join FI_ARReceiSheetLines t2 ON t.ReceivableSheetId = t2.ReceivableSheetId
WHERE t2.OutBoundLinId=FI_ARReceiSheetLines.OutBoundLinId FOR XML PATH('')), 1, 1, '') AS RecCode
FROM
FI_ARReceiSheetLines
GROUP BY FI_ARReceiSheetLines.OutBoundLinId
select RecCode from FI_ARReceivableSheets FOR XML PATH('') 将结果转换成XML
STUFF 删除指定长度的字符,并在指定的起点处插入另一组字符。
SELECT STUFF('abcdef', 2, 3, 'ijklmn')
GO
下面是结果集
aijklmnef