Concatenate many rows in one row

  • Hi,

    I Need Concatenate many rows in One row.

    For Example.

    Select id from employees

    id

    1

    2

    3

    4

    5

    I'd like....

    id

    1,2,3,4,5

    Thanks.

  • If you just want them in any old order, then it's fairly easy:

    declare @fun varchar(4000)

    set @fun='';

    select @fun= @fun+','+cast(ID as varchar(20)) from employees

    select @fun

    If you need to concatenate in a specific order - check this out:

    http://www.sqlservercentral.com/articles/Test+Data/61572/[/url]

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

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

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