help for a select

  • please help me

    sorry , Id don't speek english well

    I have a table with columns id , DateDay

    value records:

    id DateDay

    1 2015/04/01

    2 2015/04/05

    3 2015/04/01

    4 2015/04/01

    5 2015/04/05

    I want a select with group by and show example under:

    DateDay ids

    2015/04/01 1 , 3 , 4

    2015/04/05 2 , 5

    tanks

  • Rename 'mytable' as appropriate:

    SELECT DateDay,

    STUFF((SELECT ',' + CAST(SP2.ID AS VARCHAR(10)) FROM dbo.mytable SP2

    WHERE SP2.DateDay = SP1.DateDay FOR XML Path('')), 1, 1, '') ID

    FROM dbo.mytable SP1

    GROUP BY SP1.DateDay

    You could alternatively create a function to handle it if this is part of a larger query.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply