Concatenating Multiple Text Fields into one Field in another table

  • Hi,

    Could someone help me with sql code for the following? (SQL Server 2008 R2 - SQL Server 2012)

    I have spent a lot of time googling, but (and maybe I just simply don't understand) I have not

    been able to make any of the suggestions work.

    Please accept my Thanks in advance for any and all answers to my question.

    Ted

    I have Table1 Containing two fields with the below entries

    VehicleType Name

    Two Wheels Bicycle

    Two Wheels Scooter

    Two Wheels Motorcycle

    Four Wheels Sedan

    Four Wheels SUV

    Four Wheels Pickup

    Four Wheels Minivan

    The result I'm looking for would be

    Table2

    Vehicle Type

    Two Wheels Bicycle, Scooter, Motorcycle

    Four Wheels Sedan, SUV, Pickup, Minivan

  • See the following article for the answer.

    http://www.sqlservercentral.com/articles/comma+separated+list/71700/

    If you want a coded answer, see the article at the first link in my signature line below.

    --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)

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

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