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)
 Select comma separated values

Author  Topic 

ssnaik84
Starting Member

15 Posts

Posted - 2008-02-07 : 04:16:13
Hi All,
I wanna display all values of one column, separated by comma (',').
But problem is I need to display it with other columns.

I hav done it as follows:

DECLARE @temp nvarchar(4000)
SET @temp=''
SELECT DISTINCT M.Id_Message
,@temp = @temp + ',' + STO.FirstName + N' ' + STO.LastName
,M.SentDate
, ML.MessageLevel
, M.MessageSubject
, M.[Message]

FROM [Message] AS M
INNER JOIN MessageLevel AS ML
ON M.Id_MessageLevel = ML.Id_MessageLevel
INNER JOIN MessageStaff AS MS
ON M.Id_Message = MS.Id_Message
INNER JOIN Staff AS STO
ON MS.Id_Staff = STO.Id_Staff
INNER JOIN Staff AS SBY
ON M.CreatedBy = SBY.Id_Staff

WHERE M.Id_Message = 1


I got error as:
"A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations."

I donot want to make two separate select stmts.
Thanks in adv.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-07 : 04:35:45
You can't mix selecting columns and setting values for variables.
To achieve what you want, have a look at this script
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

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-02-07 : 04:38:44
see this for help:

http://www.sql-server-helper.com/error-messages/msg-141.aspx

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=367740&SiteID=1
Go to Top of Page
   

- Advertisement -