Generate single record with multiple values of stations - SQL 2000

  • Hi,

    Is there a way I could generate/populate single record with multiple values of Stations?

    Number Station Value Station1 Station2 Station3

    12345 1 10 NULL NULL NULL

    12345 2 20 NULL NULL NULL

    12345 3 30 NULL NULL NULL

    Expected result:

    Number Value Station1 Station2 Station3

    12345 10 10 20 30

    Thanks in advance!

  • Check out PIVOT in BOL. Your query would look something like this:

    SELECT Number

    , [1] AS Station1

    , [2] AS Station2

    , [3] AS Station3

    FROM

    (SELECT Number

    , Station

    , [Value]

    FROM Stations) s

    PIVOT

    (SUM([Value]) FOR Station IN ([1], [2], [3])) p

    Cath

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

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