Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2008
    Posts
    13

    Unanswered: How to concatenate rows

    Hi everyone,

    I have a table that looks like this...

    PID evacCodeNoteCd
    12 EVAC1OXY
    12 EVAC2IV
    12 EVACOTH

    and I'd like to return this...

    EVAC1OXY/EVAC2IV/EVACOTH

    So how can I concatenate multiple rows into one field?

  2. #2
    Join Date
    May 2010
    Location
    Hyderabad, India
    Posts
    16
    Declare @lvcConcat Varchar(8000)
    ,@lvcLocalVar
    SELECT @lvcConcat = ''
    Declare cursor concat_rows for
    select evacCodeNoteCd from Table_Name
    Open Cursor
    Fetch cursor into @lvcLocalVar
    WHILE(@@sqlstatus = 0)
    BEGIN
    SELECT @lvcConcat = @lvcConcat+ @lvclocalVar
    Fetch cursor into @lvcLocalVar
    END
    SELECT LTRIM(RTRIM(@lvcConcat))
    -PavanKumar M Reddy

  3. #3
    Join Date
    Sep 2008
    Posts
    13
    Thanks for the suggest. Using cursors works, but I was hoping there was a simpler solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •