首页 > 代码库 > 根据结果集 合并字符串

根据结果集 合并字符串

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

根据结果集 合并字符串