Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2011

    Unanswered: If else statement


    I have a database with a query which takes a gross yearly figure and calculates the monthly figure, e.g.

    Gross Amount / 12 = Monthly figure
    then the query also takes the monthly figure and calculates each month e.g

    monthly figure x1 = month_1
    monthly figure x2 = month_2
    monthly figure x3 = month_3
    monthly figure x4 = month_4
    monthly figure x5 = month_5
    monthly figure x6 = month_6
    monthly figure x7 = month_7
    monthly figure x8 = month_8
    monthly figure x9 = month_9
    monthly figure x10 = month_10
    monthly figure x11 = month_11
    monthly figure x12 = month_12

    I have additional fields in a table where that month may need to increase by a value, 1 field records the month 1-12 and then the other field the amount to increase the monthly figure to.
    I am wanting to write and iif statement to say something like this;

    if additional_month_1 = 1
    Then table1.addional_month_1_amt + query1.month_1
    Else if table1.additional_month_2 = 1
    then table1.addional_month_2_amt + query1.month_1
    Else if table1.additional_month_3 = 1
    then table1.addional_month_3_amt + query1.month_1
    Else if table1.additional_month_4 = 1
    then table1.addional_month_4_amt + query1.month_1
    Else query1.month_1

    Hope this makes sense and you can point me in the right direction.



  2. #2
    Join Date
    Mar 2009
    Provided Answers: 14
    IIf is not suited for this kind of operation. You'll end up with a very complex and almost unreadable expression. There probably is a way to solve this kind of problem using "pure" SQL code. Unfortunately, you don't provide any useful piece of information about the data structures that are involved.
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts