I have inherited a table that has NULL values for float
fields, instead of a 0 value. I am doing some basic testing for querying, and in my tests both ISNULL()
and COALESCE()
present the same accurate output. In my testing (a table with roughly 5K records) time difference is very negligible as well.
Question being with the sample DDL below, is there a benefit to use ISNULL()
over COALESCE()
or vice-versa? Are there circumstances that I have yet to see that could provide an inaccurate calculation?
Create Table #Test
(
blue float
,red float
,green float
)
Insert Into #Test VALUES
('14', NULL, '12')
,(NULL, '12', '10')
,(NULL, NULL, '8')
,('10', '2', NULL)
Select
ISNULL(blue,0)+ISNULL(red,0)+ISNULL(green,0)
FROM #Test
SELECT
COALESCE(blue,0)+COALESCE(red,0)+COALESCE(green,0)
FROM #Test
COALESCE
is Standard SQL supported by almost every DBMS (besides Access) whileISNULL
is MS proprietary syntax