If you have NULLable columns, you must use COALESCE or ISNULL function to convert the NULL to some comparable value, before you can compare a NULL and non-NULL value. T-SQL's COALESCE() function lets you specify a number of expressions and COALESCE() will return the first non-null value from the group.
Use the following form where expression is any data type and can equal most any valid expression
COALESCE (expression [,…n])
The function doesn't limit the number of arguments, but they must all be of the same data type; the function returns the same data type as expression.
When all arguments are NULL, COALESCE() returns NULL.
SELECT LName, FName, COALESCE (Reg, Country) AS Area FROM Employees
ORDER BY LName, FName
NOTE:: If the Reg value is null, COALESCE() returns the corresponding Country value instead.
No comments:
Post a Comment