Saturday, August 3, 2019

IsNull and COALESCE

IsNull:

Return the specified value IF the expression is NULL, otherwise return the expression:

SELECT ISNULL(NULL, 'W3Schools.com');


In SQL Server, the ISNULL( ) function is used to replace NULL value with another value.

Store_NameSales
Store A300
Store BNULL


SELECT SUM (ISNULL(Sales,100)) FROM Sales_Data;

returns the following result:
SUM (ISNULL(Sales,100))
400


COALESCE:

Return the first non-null value in a list:

SELECT COALESCE(NULLNULLNULL'W3Schools.com'NULL'Example.com');

Output:W3Schools.com








No comments:

Post a Comment

How to use SQL pagination using LIMIT and OFFSET

  How to extract just a portion of a larger result set from a SQL SELECT. LIMIT n is an alternative syntax to the FETCH FIRST n ROWS ONLY. T...