Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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')
Posted
Updated 28-May-16 23:12pm

Along the lines of:
SQL
SELECT SUBSTRING((SELECT ',' + CONVERT(varchar, MODEID) FROM MyTable FOR XML PATH('')),2,100000) AS CSV
 
Share this answer
 
Comments
Abrar Kazi 31-May-16 0:22am    
Thanks man you are awesome.
OriginalGriff 31-May-16 2:31am    
You're welcome!
As addition to Solution 1, you might benefit from this CP tip.
Concatenate rows with comma separated string[^]
 
Share this answer
 
Comments
Abrar Kazi 31-May-16 0:22am    
Thanks for the information.
George Jonsson 31-May-16 7:58am    
You are welcome.
try this
SQL
DECLARE @courierModeID VARCHAR(10000) 
SELECT @courierModeID = COALESCE(@courierModeID + ',', '') + MODEID 
FROM ( Select DIStinct MODEID from B2B_Order_Master_SAP where ORDERNO_PORTAL='OR1206') 
select @courierModeID
 
Share this answer
 
Comments
Abrar Kazi 31-May-16 0:26am    
Thank you so much for replying Karthik.
Karthik_Mahalingam 31-May-16 0:32am    
Welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900