NULLIF function in SQL Server
This article will show you in detail how to use the NULLIF function handler in SQL Server with specific syntax and examples to better visualize and capture functions.
Describe
The NULLIF function in SQL Server compares two expressions to be passed. If the first expression is equal to the second expression, NULLIF will return NULL. Otherwise, the function will return the first expression, expression 1.
Syntax
To use the NULLIF statement in SQL Server, we use the following syntax:
NULLIF(bieuthuc1, bieuthuc2)
Parameters :
- bieuthuc1, bieuthuc2: expressions to compare. The values in the expression must belong to the same data type.
Note :
- NULLIF function can be used in later versions of SQL Server: SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, and SQL Server 2005.
For example
See how to use the NULLIF statement in SQL Server.
SELECT NULLIF('TipsMake.com', 'TipsMake.com');
Result: NULL (trả về NULL vì các giá trị bằng nhau)
SELECT NULLIF('TipsMake.com', 'QuanTriMang');
Result: 'TipsMake.com' (trả về giá trị đầu tiên vì các giá trị khác nhau)
SELECT NULLIF(12, 12);
Result: NULL (trả về NULL vì các giá trị bằng nhau)
SELECT NULLIF(12, 45);
Result: 12 (trả về giá trị đầu tiên vì các giá trị khác nhau)
SELECT NULLIF('2019-05-01', '2019-05-01');
Result: NULL (trả về NULL vì các giá trị bằng nhau)
SELECT NULLIF('2019-05-01', '2019-04-30');
Result: '2019-05-01' (trả về giá trị đầu tiên vì các giá trị khác nhau)
Previous article: LEAD function in SQL Server
Next article: Function SESSION_USER in SQL Server
4.2 ★ | 12 Vote
You should read it
May be interested
- CEILING function in SQL Serverthe ceiling function in sql server returns the smallest integer value greater than or equal to the transmitted numeric expression.
- RIGHT function in SQL Serverthe article will explore and guide you how to use the right function in sql server to extract some characters from the right side of a given string.
- FLOOR function in SQL Serverthe floor function in sql server returns the largest integer value but less than or equal to the transmitted numeric expression.
- MONTH function in SQL Serverthis article will show you in detail how to use the datetime month () processing function in sql server with specific syntax and examples to better visualize and capture functions.
- DATEDIFF function in SQL Serverthis article will show you in detail how to use sql server's datetime datediff () function with syntax and specific examples to make it easier to visualize and capture functions.
- GETUTCDATE function in SQL Serverthis article will show you in detail how to use datetime getutcdate () function in sql server with specific syntax and examples to better visualize and capture functions.
- SQL Server YEAR functionsql server's year function returns a 4-digit integer that is the year value in the timestamp passed.
- COUNT function in SQL Serverthis article will show you in detail how to use functions that handle count () numbers in sql server with specific syntax and examples to better visualize and capture functions.
- LEN function in SQL Serverthe len function in sql server returns the length of the specified string. it is important that the len function does not include whitespace characters at the end of the string when calculating length.
- STR function in SQL Serverthe article will explore and show you how to use str function to return character data converted from digital data in sql server.