Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 I have a column with 5 rows - combine them

Author  Topic 

johnstern
Yak Posting Veteran

67 Posts

Posted - 2007-08-23 : 17:06:37
I have
something like this

Users
JOhn
Peter
Lucas

I would like to take all this rows and display them like so:

John, Peter, Lucas

how can i do this ?

johnstern
Yak Posting Veteran

67 Posts

Posted - 2007-08-23 : 17:12:39
I found an article showing this way

DECLARE @EmployeeList varchar(100)

SELECT @EmployeeList = COALESCE(@EmployeeList + ', ', '') +
CAST(Emp_UniqueID AS varchar(5))
FROM SalesCallsEmployees
WHERE SalCal_UniqueID = 1

SELECT @EmployeeList

and saw some post mention some issues, do you know if this a good way to do what i am trying to do
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-08-23 : 17:17:14
Thats about the way to do it. Did you get any errors?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

johnstern
Yak Posting Veteran

67 Posts

Posted - 2007-08-23 : 17:47:08
Is working fine for me, trying to break it right now but so far so good
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-24 : 05:28:33
quote:
Originally posted by johnstern

I found an article showing this way

DECLARE @EmployeeList varchar(100)

SELECT @EmployeeList = COALESCE(@EmployeeList + ', ', '') +
CAST(Emp_UniqueID AS varchar(5))
FROM SalesCallsEmployees
WHERE SalCal_UniqueID = 1

SELECT @EmployeeList

and saw some post mention some issues, do you know if this a good way to do what i am trying to do


If the concatenated string exceeds more than varchar length, you should use more than one variable. If you want to show the data at front end application, you can easily concatenate there



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-24 : 05:42:59
Use the faster SQL Server 2005 approach!
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -