Tuesday, March 27, 2012

convert 0 or NULL to 1 for devision purpose

hi,

I have data like 0, null or some value in one column. I want to use
this column for devision of some other column data.

It gives me devision by 0 error.

how can I replace all 0 and null with 1 in fly.

thanks in adv.

t.s.negiDivision by NULL should produce a NULL result, not an error. If you want to
change NULL and 0 to 1 then change your division expression to:

x / CASE WHEN col<>0 THEN col ELSE 1 END

However, a more usual way of avoiding the division by zero error is to
change zeros to NULL:

x / NULLIF(col,0)

giving a NULL result for division by zero, which makes sense for many
applications.

--
David Portas
----
Please reply only to the newsgroup
--|||Thanks,
David Portas

x / NULLIF(col,0)
will work

T.S.Negi

No comments:

Post a Comment