When writing SQL, using built-in functions can save you time by ensuring data validation, managing null values, and working with dates. In this post, we will review five popular SQL functions that every developer or data analyst should know:
- ISNUMERIC()
- ISDATE()
- ISNULL()
- NULLIF()
- GETDATE()
ISNUMERIC():
Checks whether a given expression can be evaluated as a number.
SELECT ISNUMERIC('123'); -- Returns 1 (True)
SELECT ISNUMERIC('abc'); -- Returns 0 (False)
SELECT ISNUMERIC('123.45'); -- Returns 1 (True)
Note:
ISNUMERIC()
may return 1 for values like +
, -
, and e
, which can lead to confusion. For stricter checks, use TRY_CAST()
.
ISDATE():
Determines if a value is a valid date.
SELECT ISDATE('2025-07-25'); -- Returns 1
SELECT ISDATE('31-02-2024'); -- Returns 0
SELECT ISDATE('Hello'); -- Returns 0
ISNULL():
Replaces NULL
with a specified replacement value.
SELECT ISNULL(NULL, 'N/A'); -- Returns 'N/A'
SELECT ISNULL('Hello', 'N/A'); -- Returns 'Hello'
NULLIF():
Returns NULL
if two expressions are equal. Otherwise, returns the first expression.
SELECT NULLIF(100, 100); -- Returns NULL
SELECT NULLIF(100, 50); -- Returns 100
GETDATE():
Returns the current system date and time (as datetime
).
SELECT GETDATE(); -- Returns something like: 2025-07-25 14:32:11.123
š Thank You for Reading!
Thank you for taking the time to read this blog!
If you have any questions or need help with something, feel free to drop a message in the comments or contact section. Iāll get back to you as soon as possible.
Happy Learning! š