Thursday, February 25, 2010

NULLIF

Do you remember NULLIF function?
What would be the output of the following scripts?
DECLARE @Test TABLE (a INT, b INT)
INSERT @Test VALUES(1,NULL)
INSERT @Test VALUES(NULL,2)
INSERT @Test VALUES(0,3)
INSERT @Test VALUES(NULL,4)
INSERT @Test VALUES(5,0)
SELECT SUM(NULLIF(COALESCE(a,b), 0.00))
FROM @Test

A. 14
B. 6
C. 9
D. 12
E. 8
F. 7

Answer:[D]
Highlight to find out the answer.

No comments:

Post a Comment