Pivot Table

  • CREATE TABLE [dbo].[TableTemp](

    [BASEL_CATEGORY] [varchar](50) NULL,

    [EC_DRAWN] [numeric](18, 6) NULL,

    [EC_UNDRAWN] [numeric](18, 6) NULL,

    [EC_DRAWN_R] [numeric](18, 6) NULL,

    [EC_UNDRAWN_R] [numeric](18, 6) NULL,

    [EC_DRAWN_S] [numeric](18, 6) NULL,

    [METHOD] [varchar](10) NULL

    ) ON [PRIMARY]

    INSERT INTO [dbo].[TableTemp]

    ([BASEL_CATEGORY]

    ,[EC_DRAWN]

    ,[EC_UNDRAWN]

    ,[EC_DRAWN_R]

    ,[EC_UNDRAWN_R]

    ,[EC_DRAWN_S]

    ,[METHOD])

    VALUES

    ('x'

    ,0.006

    ,0.09

    ,0.098

    ,1.34

    ,1.67

    ,'STD')

    INSERT INTO [dbo].[TableTemp]

    ([BASEL_CATEGORY]

    ,[EC_DRAWN]

    ,[EC_UNDRAWN]

    ,[EC_DRAWN_R]

    ,[EC_UNDRAWN_R]

    ,[EC_DRAWN_S]

    ,[METHOD])

    VALUES

    ('x'

    ,0.045

    ,0.037

    ,0.048

    ,1.38

    ,1.60

    ,'airb')

    INSERT INTO [dbo].[TableTemp]

    ([BASEL_CATEGORY]

    ,[EC_DRAWN]

    ,[EC_UNDRAWN]

    ,[EC_DRAWN_R]

    ,[EC_UNDRAWN_R]

    ,[EC_DRAWN_S]

    ,[METHOD])

    VALUES

    ('y'

    ,2.006

    ,7.09

    ,9.098

    ,0.34

    ,7.67

    ,'STD')

    INSERT INTO [dbo].[TableTemp]

    ([BASEL_CATEGORY]

    ,[EC_DRAWN]

    ,[EC_UNDRAWN]

    ,[EC_DRAWN_R]

    ,[EC_UNDRAWN_R]

    ,[EC_DRAWN_S]

    ,[METHOD])

    VALUES

    ('y'

    ,5.006

    ,7.09

    ,9.098

    ,2.34

    ,6.67

    ,'airb')

    select * from [dbo].[TableTemp]

    --Output Table

    Economic_capitaL X Y Z.......COLUMN HEADERS

    EC (drawn) – aIRB

    EC (drawn)– Std

    EC (undrawn) – AIRB

    EC (undrawn) – Std

    EC (drawn S) – AIRB

    EC (drawn S) – Std

    EC (drawn R) – AIRB

    EC (drawn R) – Std

    EC (undrawn R) – AIRB

    EC (undrawn R) – Std

    ** these are fixed rows

    ** category have many values all categories should come as column headers

    **Note there are only two methods

  • Duplicate post. No replies to this thread please. Direct replies to:http://www.sqlservercentral.com/Forums/Topic1332742-392-1.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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