
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 :
Note :
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
ncG1vNJzZmismaXArq3KnmWcp51ku7a4y6KdZp6lo7C1tc6nZKKmXai%2BrXnSnqmvnaI%3D