• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2267
  • Last Modified:

sql 2000 concatenate text field by aggregate function

I've got a table that contains email addresses, and I would like to return a single string with all of the email addresses concatenated and separated by commas.

For example:

table1
----------
mark@dummy.com
bill@hotmail.com
gene@aol.com

returned query would return:

mark@dummy.com,bill@hotmail.com,gene@aol.com

I really would prefer not to have to make a stored procedure with a cursor, as this list could be exceptionally long and may hog alot of system resources if done that way.

my environment:  sql 2000 sp3 running on windows server 2003 sp1

0
divi2323
Asked:
divi2323
1 Solution
 
rafranciscoCommented:
Try this:

DECLARE @Emails VARCHAR(8000)

SELECT @Emails = ISNULL(@Emails + ',', '') + Email
FROM Table1

SELECT @Emails AS Emails
0
 
divi2323Author Commented:
worked perfectly.  and with so little code.  much thanks.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now