根据结果集 合并字符串

时间:2021-11-09 18:48:22

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