SQL SERVER: COALESCE FUNCTION
This SQL Server tutorial explains how to use the COALESCE function in SQL Server (Transact-SQL) with syntax and examples.
DESCRIPTION
The SQL Server (Transact-SQL) COALESCE function returns the first non-null expression in the list. If all expressions evaluate to null, then the COALESCE function will return null.
SYNTAX
The syntax for the COALESCE function in SQL Server (Transact-SQL) is:
COALESCE( expression1, expression2, ... expression_n )
Parameters or Arguments
- expression1 to expression_n
- The expressions to test for non-null values.
APPLIES TO
The COALESCE function can be used in the following versions of SQL Server (Transact-SQL):
- SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005
EXAMPLE
Let's look at some SQL Server COALESCE function examples and explore how to use the COALESCE function in SQL Server (Transact-SQL).
For example:
SELECT COALESCE(NULL, NULL, 'mindsforest.com', NULL, 'abc.com'); Result: 'mindsforest.com' SELECT COALESCE(NULL, 'mindsforest.com', 'abc.com'); Result: 'mindsforest.com' SELECT COALESCE(NULL, NULL, 1, 2, 3, NULL, 4); Result: 1
0 comments:
Post a Comment