How to manage NULL values in numeric fields returned by cursor in Select stament, to manage efficienly aritmetic operations ?
+3
A:
Don't use cursors.
If you must (really?), you can use the ISNULL function:
SELECT ISNULL(fieldname, 0)
will give you a "0" (zero) instead of NULL.
marc_s
2009-11-24 15:46:33
+3
A:
ISNULL(value, replacement)
will replace value
with replacement
if value
IS NULL
Nick Spiers
2009-11-24 15:47:33
+1
A:
Assuming you cannot avoid a cursor in the first place, I don't understand why a NULL
would be handled much differently in a variable than you would in a query - there is INSULL
, COALESCE
, CASE WHEN
etc.
One interesting thing:
DECLARE @v as int -- initialized to NULL
{ -- loop through a cursor
FETCH NEXT INTO @v
}
You won't be able to necessarily distinguish an uninitialized @v
from when the last row's @v
setting was NULL
.
Cade Roux
2009-11-24 15:51:02