Returning the First Non NULL Value in a List of Expressions : COALESCE « Data Convert Functions « SQL Server / T-SQL Tutorial






5> DECLARE @Value1 int
6> DECLARE @Value2 int
7> DECLARE @Value3 int
8> SET @Value2 = 22
9> SET @Value3 = 955
10> SELECT COALESCE(@Value1, @Value2, @Value3)
11> GO

-----------
         22

(1 rows affected)
1>








13.2.COALESCE
13.2.1.COALESCE is equivalent to a CASE expression that returns the first NOT NULL expression in a list of expressions.
13.2.2.Returning the First Non NULL Value in a List of Expressions
13.2.3.COALESCE() saves quite a lot of IF or CASE decision logic.
13.2.4.A SELECT statement that uses the COALESCE function
13.2.5.A SELECT statement that substitutes a different data type