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

上一篇:Java设计模式-创建型模式之简单工厂模式


下一篇:Google团队在DNN的实际应用方式的整理