Code transform

G

Guest

I have this T-SQL code:
CASE WHEN GrossIncome < 0 AND
NetIncome < 0 THEN - 1 * IsNull(NULLIF (NetIncome, 0) / NULLIF (GrossIncome,
0) * 100, 0)
ELSE IsNull(NULLIF (NetIncome, 0) / NULLIF (GrossIncome,
0) * 100, 0)
END AS [GP%]

And I'm trying to do the same thing on a form:
= If GrossIncome < 0 AND NetIncome < 0
THEN - 1 * IsNull(NULLIF (NetIncome, 0) / NULLIF (GrossIncome, 0) * 100, 0)
ELSE IsNull(NULLIF (NetIncome, 0) / NULLIF (GrossIncome, 0) * 100, 0)

but am getting errors. Basically I'm trying to prevent DIV0 errors.

many thanks
 
D

Douglas J. Steele

In general, the equivalent of IsNull is NZ, the equivalent of
CASE...ELSE...END is Iif* and the equivalent of NULLIF would be IIf(a = b,
a, Null)

Not sure I understand what your code is supposed to be doing, though.
Certainly the first case (GrossIncome < 0 AND NetIncome < 0) shouldn't
require the used of NULLIF or IsNull, since you know that neither value is 0
or Null.

* only true if you've got CASE WHEN ... ELSE ... END, as opposed to multiple
WHEN choices)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top