How to get column value as column name

  • Hi

      I have a table which has values

    Description                              Value

    Tiering                                      N/A

    Strategic Overview                     N/A

    Tier Pricing Report                      In Progress

    Store Pricing Report                    N/A

    Price Implement                         Done

    Tracking Report                         N/A

     

    I need a query which would have the result like

    Tiering      StrategicOverView   TierPricing     StorePricingReport

       N/A           N/A                    In Progress      N/A

     

    How could i get this?

    Thanks,

    Sridhar!!

     

     

  • SELECT MIN(CASE Description WHEN 'Tiering' THEN Value ELSE NULL END) AS Tiering,

    SELECT MIN(CASE Description WHEN 'Strategic Overview' THEN Value ELSE NULL END) AS StrategicOverview,

    SELECT MIN(CASE Description WHEN 'Tier Pricing Report' THEN Value ELSE NULL END) AS TierPricing,

    SELECT MIN(CASE Description WHEN 'Store Pricing Report' THEN Value ELSE NULL END) AS StorePricingReport

    FROM YourTable

    --
    Adam Machanic
    whoisactive

  • Thanks Adam,

     

       That worked.

     

    Sridhar!!

  • hey sridar

    could u plz explain how u solved the pblm.i did not understand. i get error when i did the same

    thanx

    Rajiv.

  • Rajiv,

    What error did you get?

    --
    Adam Machanic
    whoisactive

  • Hey Rajiv,

     u will get it very clear with following query.It's same as above but slight change.

    SELECT MIN(CASE Description WHEN 'Tiering' THEN Value ELSE NULL END) AS Tiering,

     MIN(CASE Description WHEN 'Strategic Overview' THEN Value ELSE NULL END) AS StrategicOverview,

     MIN(CASE Description WHEN 'Tier Pricing Report' THEN Value ELSE NULL END) AS TierPricing,

    MIN(CASE Description WHEN 'Store Pricing Report' THEN Value ELSE NULL END) AS StorePricingReport

    FROM YourTable

     

    Thanks

    Yuvraj

  • Good catch Yuvraj... I was too quick on the copy and paste, I'm afraid!

    --
    Adam Machanic
    whoisactive

  • hey adam and yuvraj

    thanx for all ur efforts. sorry for not replying for a long time.

    my doubt::

    what is that "min( )" doing there?

    when i used it...i got error.

    select * from reg

    regis       rname               

    ----------- --------------------

    1234        a

    5678        b

    8901        c

    select  (select case when rname='a' then regis end ) as a,

            (select case when rname='b' then regis end ) as b,

     (select case when rname='c' then regis end) as c

    from reg

    a           b           c          

    ----------- ----------- -----------

    1234        NULL        NULL

    NULL        5678        NULL

    NULL        NULL        8901

    now how to avoid this null values???

    i neeed to get it as

    a

  • hey all

    now i got it....sorry for the trouble!!!

    now i understand u Yuvraj.....also the function of "min" is clear.anything min or max would work...

    thanx a lot....

    Rajiv.

Viewing 9 posts - 1 through 8 (of 8 total)

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