sql 多行拼接 成一行

2021/12/7 2:24:35

本文主要是介绍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=''



这篇关于sql 多行拼接 成一行的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程