A way to avoid repeating case statement

  • Hello,

    Is there a way to avoid repeating a case statement. If the first is true, there is an amount subtracted from the result of the Case Statement. If if it is false, just the case statement result is printed. See below for an example. I hope this makes sense.

    CASE WHEN TestField >0 THEN 

               ( CASE WHEN SalesField = 'B' THEN SalesAmount

                         WHEN Sales2Field = 'C' THEN Sales2Amount

                         WHEN Sales3Field = 'D' THEN Sales3Amount 

                         ELSE 0 END) - TestField

             ELSE         

                 ( CASE WHEN SalesField = 'B' THEN SalesAmount

                         WHEN Sales2Field = 'C' THEN Sales2Amount

                         WHEN Sales3Field = 'D' THEN Sales3Amount 

                         ELSE 0 END)

  • Disregard - I found a solution by adding the Testfield after the minus sign as it's own case statement.

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

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