• So, what you are looking for is:

    Col1, comma-separated list of Column 2 (in order)

    Col1 should only be there once.

    Col2 is an integer, and should be sorted by it's value.

    Is this correct?

    So, this is what you're looking for:

    DECLARE @table TABLE (

    Col1 INT,

    Col2 INT);

    INSERT INTO @table (Col1, Col2)

    SELECT 1, 1 UNION ALL

    SELECT 1, 2 UNION ALL

    SELECT 1, 5 UNION ALL

    SELECT 1, 10 UNION ALL

    SELECT 3, 1 UNION ALL

    SELECT 3, 5 UNION ALL

    SELECT 3, 10 UNION ALL

    SELECT 3, 15;

    WITH cte AS

    (

    SELECT DISTINCT Col1

    FROM @table

    )

    SELECT Col1,

    CS = STUFF((SELECT ',' + CONVERT(VARCHAR(10), Col2)

    FROM @table t1

    WHERE t1.col1 = cte.Col1

    ORDER BY Col2

    FOR XML PATH(''), TYPE).value('.','varchar(max)'),

    1, 1, '')

    FROM cte

    ORDER BY Col1;

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2