sql 2000 concatenate text field by aggregate function

Posted on 2005-05-11
Last Modified: 2008-08-25
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:


returned query would return:,,

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

Question by:divi2323
    LVL 28

    Accepted Solution

    Try this:

    DECLARE @Emails VARCHAR(8000)

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

    SELECT @Emails AS Emails
    LVL 4

    Author Comment

    worked perfectly.  and with so little code.  much thanks.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction If you are not already aware of what you could use a table with sequential integer values for in SQL, you can read Delimited String Parsing in SQL Server 2005 or later ( by BrandonGalderisi (h…
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now