ISNULL and nullif in SQL Server

Source: Internet
Author: User

There are two parameters in SQL Server, syntax:
ISNULL (Check_expression, Replacement_value)

Check_expression and Replacement_value data types must be consistent
If Check_expression is NULL, the Replacement_value is returned
If Check_expression is not NULL, the check_expression is returned

Nullif is used to check two expressions, syntax:

Nullif (expression, expression)

If two expression equals, returns NULL, which is the data type of the first expression
Assuming that two expression is not equal, the first expression is returned

The descriptions of two functions in SQL Server that are inferred to be null are NULLIF and isnull such as the following:
Nullif: Requires two parameters, assuming two of the specified expressions are equivalent, returns null
Example: Nullif (A, B)
Description: Assuming that A and B are equal, then return null, assuming unequal returns a
Select Nullif (' eqeqweqwe ', ' 1 ') turns out to be eqeqweqwe
Select Nullif () result is null
The type of a and B should be consistent
ISNULL: Requires two parameters, the goal is to replace NULL with the specified value, and if the first parameter is not NULL, the first parameter is returned
Example: ISNULL (A, B)
Description: Assume that A and B are null at the same time, return NULL, assume that A is null,b not NULL, return B, assume that A is not NULL for NULL,B and return a, assuming that both A and B are not NULL to return a
Select ISNULL (null,null) result is null
Select ISNULL (null,33) results are 33
Select ISNULL (' DDD ', null) result is DDD
Select ISNULL (44,33) results are 44
IsNumeric: Verify that the expression is a valid numeric form

ISNULL and nullif in SQL Server

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.