ISNULL and NULLIF in SQL Server

Source: Internet
Author: User

SQL Server has two parameters. Syntax:
ISNULL (check_expression, replacement_value)

The check_expression and replacement_value data types must be consistent.
If check_expression is NULL, replacement_value is returned.
If check_expression is not NULL, check_expression is returned.

NULLIF is used to check two expressions. Syntax:

NULLIF (expression, expression)

If two expressions are equal, NULL is returned, which is the data type of the first expression.
If two expressions are not equal, the first expression is returned.

The two functions NULLIF and ISNULL in SQL Server are described as follows:
NULLIF: two parameters are required. If the two specified expressions are equivalent, null is returned.
Example: NULLIF (a, B)
Note: If a and B are equal, NULL is returned. If not, a is returned.
Select NULLIF ('eqeqweqw', '1'). The result is eqeqweqwe.
Select NULLIF () returns NULL
The types of a and B must be consistent.
ISNULL: two parameters are required. The objective is to replace null with the specified value. If the first parameter is not null, the first parameter is returned.
Example: ISNULL (a, B)
NOTE: If both a and B are NULL, NULL is returned. If a is NULL and B is not NULL, B is returned. If a is not NULL and B is NULL, a is returned, if neither a nor B is NULL, a is returned.
Select ISNULL (null, null) returns null
The result of select ISNULL (null, 33) is 33.
Select ISNULL ('ddd ', null) results in ddd
Select ISNULL () result is 44
Isnumeric: Check whether the expression is a valid number.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.