Dynamic column name

  • Can any one answer the following

    i have two tables like TabA and TabB

    In  TabA contains column like  'code' it holds char. ex : 'A', 'B' and etc

    In TabB having data for the corresponding code  with separate column ex:  DataA, DataB,.....

    here i have to query the  data from TabB by corresponding code..

    ex: select tabB.Code, tabB.data<code> from ...

    is there any way to evaluate column name while runtime

    Thanks

    Kalai

     

     


    Kindest Regards,

    Kalai

  • Yes, with Case, i.e. (the query of course depends on how to stick taba and tabb together):

    SELECT

    TabA....

    CASE

    WHEN TabA.code='A' THEN TabB.DataA

    WHEN TabA.code='B' THEN TabB.DataB

    ...

    ELSE 'x'

    END AS data

    FROM

    TabA

    LEFT JOIN TabB ON TabB.whatever = TabA.whatever

  • Thank u Gross, it works well.

    Thanks

    Kalai

     

     


    Kindest Regards,

    Kalai

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

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