Thursday, November 3, 2011

IsNull and NullIf

IsNull and NullIf sounds same but has different fundtion in SQL.
IsNull replaces Null with the specified argument.
NullIf returns NULL if the specified two argument are equal.
DECLARE @String nValchar(15) = ''
SELECT NullIf(LEN(@String), 0) 
-- This will return Null because specified variable's length is 0 and both parameters are equal.
SELECT IsNULL(@String, 'No Value')
-- This will return '' string because @String is not Null.

No comments:

Post a Comment