How t开发者_JS百科o manage NULL values in numeric fields returned by cursor in Select stament, to manage efficienly aritmetic operations ?
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.
ISNULL(value, replacement)
will replace value with replacement if value IS NULL
http://msdn.microsoft.com/en-us/library/ms184325.aspx
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.
加载中,请稍侯......
精彩评论