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 2000 Forums
 SQL Server Development (2000)
 Select columns as a comma delimited string

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-01-31 : 21:33:27
a29379 writes "I have on table with people. SQL7.0 sp3 WinNT. It has a one-to-many relationship with a table Emails. I want to select a persons name and his emailaddresses, The emailadresses as a comma delimited string.

Like this:
Orvar Dyvelpung "aaa@bbb.com","bbb@ccc.nu","ccc@ddd.no"

My solution for now looks like this:

DECLARE @blah varchar(8000)
SET @blah= ''
SELECT @blah = @blah + '"' + Email + '"' + ','
FROM Emails
WHERE RowId = @RowId
IF datalength(@blah) > 0
SET @blah = left(@blah, datalength(@blah) - 1 )
SELECT @blah

I want to get rid of the local variable and do it all in ONE select.

How?"
   

- Advertisement -