Sql Server

SQL | Handle Null

SQL | Handle Null

Handle Null

IS NULL
IS NULL operator is to compare the values with Null in the table. It occupies 0-byte memory.

ISNULL() accepts two arguments:
- expression :-  an expression of any type that is checked for NULL.
- replacement :- is the value to be returned if the expression is NULL. The replacement must be convertible to a value of the type of the expression.


Returns
The ISNULL() function returns the replacement if the expression evaluates to NULL. Before returning a value, it implicitly converts the type of replacement to the type of the expression if the types of the two arguments are different. In case the expression is not NULL, the ISNULL() function returns the value of the expression.


SELECT ISNULL(NULL,20) result;
//Return 20

SELECT ISNULL(ListPrice, 0) Result from products;


-- With Agreegate function
SELECT SUM(ISNULL(fees, 10000)) FROM Students;


-- With Variable
DECLARE @ID DateTime2
SELECT ISNULL(@ID, CURRENT_TIMESTAMP);




IS NULL command
The IS NULL command is used to test for empty values (NULL values).SELECT *

FROM Students
WHERE fees IS NULL;


A NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation!
Always use IS NULL to look for NULL values.



Related Post

About Us

Community of IT Professionals

A Complete IT knowledgebase for any kind of Software Language, Development, Programming, Coding, Designing, Networking, Hardware and Digital Marketing.

Instagram