sql 多行拼接 成一行

--不去重

SELECT
T1.DELIVERY_DATE
,T.INNER_NO
,stuff((SELECT '/'+CONT_2040 FROM SPECIAL_DNSEN.dbo.DNSEN_CONTAINER_NAME AS A WHERE A.INNER_NO=T.INNER_NO for xml path ('')),1,1,'') as CONT_NAME--需要拼接的表
FROM DBO.COP_ACT_I_HEAD AS T--需要关联的表
LEFT JOIN COP_LOGISTICS_TRACKING AS T1 ON T.INNER_NO=T1.BILL_NO AND T.SITE=T1.SITE
WHERE T.SEQ_NO=''

 

--去重拼接

SELECT
T1.DELIVERY_DATE
,T.INNER_NO
,stuff((SELECT distinct('/'+CONT_2040) FROM SPECIAL_DNSEN.dbo.DNSEN_CONTAINER_NAME AS A WHERE A.INNER_NO=T.INNER_NO for xml path ('')),1,1,'') as CONT_NAME
FROM DBO.COP_ACT_I_HEAD AS T
LEFT JOIN COP_LOGISTICS_TRACKING AS T1 ON T.INNER_NO=T1.BILL_NO AND T.SITE=T1.SITE
WHERE T.SEQ_NO=''

posted @ 2021-12-06 14:52  饮水思源^0^  阅读(604)  评论(0编辑  收藏  举报