I need to take every item in a column (only like 50 of them) and concantenate into one string..

So, a column name designation, I want to take all the designations and return one string with all those designations seperated by a comma.

For example the returned result would be: "Des1, Des2, Des3, Des4 etc.."


 I want to do this in SQL, because I will probably need to do this often.

Thanks! :)
LVL 5
syeager305Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
dba2dbaConnect With a Mentor Commented:
DECLARE @Description varchar(100)  
SELECT @Description = COALESCE(@Description + ', ', '') + column1
FROM table1
SELECT @Description
0
 
wdosanjosConnect With a Mentor Commented:
Try something like this:

SELECT NameDesignation + ', '
   FROM YourTable
   FOR XML PATH( '' )  
0
 
SharathData EngineerCommented:
>>  I want to do this in SQL,

SQLServer 2000 or SQL Server 2005 or MySQL?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
MadRacer1Commented:
DECLARE @Result VARCHAR(500)

// Combine all designations in one variable with comma separation
SELECT @Result=@Result+’,’ FROM Table

// remove last comma from Combined Designations,
SELECT LEFT( @Result,LEN(@Result)-1) AS CombinedDesignations
0
 
MadRacer1Connect With a Mentor Commented:
DECLARE @Result VARCHAR(500)
SET @Result  =''

// Combine all designations in one variable with comma separation
SELECT @Result=Designation+ ',' + @Result  FROM Table

// remove last comma from Combined Designations,
SELECT LEFT( @Result,LEN(@Result)-1) AS CombinedDesignations
0
 
syeager305Author Commented:
Yes, all solutions worked, dba2dba I gave 200 because he was the first to respond. But wdosanjos your solution was different, i tried it I'm not familiar with that coding - it worked, so thank you.
Madracer1, similar to dba2dba but with no coalesce, it worked as well.

Thank you experts! :)
0
All Courses

From novice to tech pro — start learning today.