Code transform

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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)
 
Back
Top