• Ya beat me to it, John. 🙂

    Not 100% sure but, using your good data, I think example 1 was meant to be something on the order of...

    -- Example 1

    DECLARE @EMail VARCHAR(8000)

    SELECT @EMail = COALESCE(@EMail + ', ', '') + t1.ColumnB

    FROM dbo.Table1 t1

    INNER JOIN dbo.Table2 t2 ON t1.ColumnA = t2.ColumnA

    WHERE t2.ColumnD = 'EMail'

    SELECT @EMail

    GO

    ...and the output was meant to be something like this...

    ---------------------------------------------------------------------------------------------------------------------------------

    Michael.Jordan@domain.com, Lebron.James@domain.com, Kobe.Bryant@domain.com, Earvin.Johnson@domain.com, Charles.Barkely@domain.com

    (1 row(s) affected)

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)