数据库
首页 > 数据库> > sql 多行拼接 成一行

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=''

标签:多行,COP,CONT,NO,T1,拼接,INNER,sql,SELECT
来源: https://www.cnblogs.com/lacey/p/15649910.html