trim comma delimited values in a single row to multiple rows

  • Hi, I want to know if anyone can help me trim values of comma delimited types into multiple rows. Below is an illustration of what i want to achieve. thanks

    CARKEYCARTYPEDEFECTKEYS
    1CAR A1250
    2CAR B126, 4548, 1250
    3CAR C6548
    4CAR D245, 9845, 5664, 3654, 1001
    CARKEYCARTYPEDEFECTKEYS
    1CAR A1250
    2CAR B126
    2CAR B4548
    2CAR B1250
    3CAR C6548
    4CAR D245
    4CAR D9845
    4CAR D5664
    4CAR D3654
    4CAR D1001
  • Using the function fnParseList here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033

    INSERT NewTable (CarKey, CarType, DefectKeys)

    SELECT t.CarKey, t.CarType, LTRIM(RTRIM(x.Data))

    FROM OldTable AS t

    CROSS APPLY dbo.fn(',', t.DefectKeys) AS x

     


    N 56°04'39.16"
    E 12°55'05.25"

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

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