253.
What will the last two lines print? DECLARE @test VARCHAR(2) DECLARE @first VARCHAR(4) DECLARE @second VARCHAR(4) SELECT @first = ISNULL(@test, 'test') SELECT @second = COALESCE(@test, 'test') PRINT @first PRINT @second
View Description
ISNULL() accepts two parameters. The first is evaluated, and if the value is null, the second value is returned (regardless of whether or not it is null). The following queries will return the second parameter in both cases: SELECT ISNULL(NULL, 1) --Returns 1 SELECT ISNULL(NULL, NULL) --Returns NULL Coalesce returns the first non-null expression in a list of expressions. The list can contain two or more items, and each item can be of a different data type. The following are valid examples of COALESCE: SELECT COALESCE(NULL, 1) --Returns 1 SELECT COALESCE(NULL, 3, NULL, 1) --Returns 3