我需要转换下面的查询以供SQL Server使用。有什么想法如何转换此ListAgg查询以供SQL Server使用吗?
moduleFixture.createNestApplication()
答案 0 :(得分:0)
您可以尝试一下。
;WITH CTE AS (
select
A.CONTRACT_ID,
A.CONTRACT_ref_num,
A.BA_INT_ID,
B.WHOLE_NAME
from
MN_BA_INT A
INNER JOIN MN_BA_INT_WHOLE B ON A.BA_INT_ID=B.BA_INT_ID
INNER JOIN MN_STRUCTURED_DOC C ON A.CONTRACT_ID=C.struct_doc_id
)
SELECT CONTRACT_ID, CONTRACT_ref_num, BA_INT_ID,
STUFF( ( SELECT ' | ' + WHOLE_NAME
FROM CTE T2
WHERE T1.CONTRACT_ID = T2.CONTRACT_ID
AND T1.CONTRACT_ref_num = T2.CONTRACT_ref_num
AND T1.BA_INT_ID = T2.BA_INT_ID
ORDER BY CONTRACT_ID DESC FOR XML PATH('') ) ,1,3,'') AS Distributors FROM CTE T1
group by
CONTRACT_ID, CONTRACT_ref_num, BA_INT_ID