Crosstab query in SQL 2000

  • There is a table as below.

    ID SEQ CODE

    1001A

    1002B

    1011D

    1012E

    1013X

    How to code to list as cross tab like below?

    ID CODE1 CODE2 CODE3

    100 A B

    101 D E X

  • SELECT

    ID

    , MAX(CASE WHEN SEQ = 1 THEN CODE ELSE NULL END) CODE1

    , MAX(CASE WHEN SEQ = 2 THEN CODE ELSE NULL END) CODE2

    , MAX(CASE WHEN SEQ = 3 THEN CODE ELSE NULL END) CODE3

    FROM

    MYTABLE

    GROUP BY

    ID

    ?

    I Have Nine Lives You Have One Only
    THINK!

  • It works great.

    Thanks

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

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