How to put IF conditions on COLUMN NAMES...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • didajosh
    New Member
    • Aug 2008
    • 47

    How to put IF conditions on COLUMN NAMES...

    Hi,



    My table is like

    A/C_NO----BUD_00------YTD_00------BUD_01-----YTD_01-----BUD_02-----YTD_02
    014-----------1000------------10---------------1000---------20------------1100-----------30

    the result I want is something like:


    A/C_NO----BUD_01------EXP_01
    014-----------1000------------10

    BUD shows the budget
    EXP_01, is the EXPENSE in period 01,
    which is calculate as the period specific expense and calculated as
    (YTD_01) - (YTD_00).

    User selects, which period, he wants the information for, like 00,01,02

    How do I do this….I am clueless…. :-o

    -dipali
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    in which part you want to use IF condition ?

    Comment

    • amitpatel66
      Recognized Expert Top Contributor
      • Mar 2007
      • 2358

      #3
      I think from the information that you have provided you are looking at using a WHERE condition in your query.

      SOmething like SELECT col1,col2,col3 FROM table_name WHERE period = '00' (This can be a input parameter and can user pass in the value 00,01 or 02)

      Comment

      • didajosh
        New Member
        • Aug 2008
        • 47

        #4
        Thank you all, this issue had been resolved.

        Comment

        • Pilgrim333
          New Member
          • Oct 2008
          • 127

          #5
          Hi,

          Explaining your solution could help others.

          Pilgrim.

          Comment

          • didajosh
            New Member
            • Aug 2008
            • 47

            #6
            I used CASE here.
            e.g
            select column names,
            (CASE
            when (:PERIOD) = ('01')
            THEN ((YTD_01) - (YTD_00))

            WHEN (:PERIOD) = ('02')
            THEN ((YTD_02) - (YTD_01))

            END)
            as EXPENSE


            Regards,
            Dipali

            Comment

            Working...