本文介绍了如何在SELECT QUERY中选择逗号分隔的多个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MY TABLE价值



MODEID(Col名称)

01

05







必需输出:



@ ModeID varchar(200)

@ModeID = 01,05,06等



我尝试过:



声明@courierModeID varchar(200)

select @courierModeID =(从B2B_Order_Master_SAP中选择DIStinct MODEID,其中ORDERNO_PORTAL ='OR1206')

MY TABLE Values

MODEID (Col Name)
01
05
.
.
.
Required Output :

@ModeID varchar(200)
@ModeID =01,05,06,etc

What I have tried:

declare @courierModeID varchar(200)
select @courierModeID = (Select DIStinct MODEID from B2B_Order_Master_SAP where ORDERNO_PORTAL='OR1206')

推荐答案

SELECT SUBSTRING((SELECT ',' + CONVERT(varchar, MODEID) FROM MyTable FOR XML PATH('')),2,100000) AS CSV



DECLARE @courierModeID VARCHAR(10000)
SELECT @courierModeID = COALESCE(@courierModeID + ',', '') + MODEID
FROM ( Select DIStinct MODEID from B2B_Order_Master_SAP where ORDERNO_PORTAL='OR1206')
select @courierModeID


这篇关于如何在SELECT QUERY中选择逗号分隔的多个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:12