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

    Unanswered: Divission in sql when case statement is involved

    Here is one new problem. I have 2 calculated fields and they are ratios ex: a/b and c/d. When i am calculating it i used 'CASE WHEN b=0 then outputcolumn = 0 else a/b END' similarly
    'CASE WHEN d=0 then outputcolumn = 0 else c/d END '. Now i want to subtract these 2 calculated fields and get one more calculated field. How can I do that? Can anybody help me in this issue?

  2. #2
    weejas is offline Grumpy old man (training)
    Join Date
    Sep 2006
    Surrey, UK
    Provided Answers: 18
    You can either carry them out as a subquery, which will involve a performance hit, or try
    (CASE WHEN b=0 THEN 0 ELSE a/b) - (CASE WHEN d=0 THEN 0 ELSE c/d)
    10% of magic is knowing something that no-one else does. The rest is misdirection.
    Beers earned: 2

Posting Permissions

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