SQL Server ISNUMERIC() Function
The ISNUMERIC()
function in SQL Server checks if a given expression can be converted to a numeric data type. This is extremely useful for data validation, ensuring that values intended to be numbers are actually in a numeric format.
ISNUMERIC(): Definition and Usage
ISNUMERIC()
is a valuable tool for cleaning and preparing data. It helps you identify non-numeric entries that might cause errors in your queries or calculations. It returns 1 if the expression can be interpreted as a number, and 0 otherwise.
Syntax
Syntax
ISNUMERIC(expression)
Parameter Values
Parameter | Description |
---|---|
expression |
The expression you want to check. This can be a literal value (number or string), a column name, or a more complex expression. This is required. |
Examples
Testing a Numeric Literal
Checking if a number is numeric (it is!).
Syntax
SELECT ISNUMERIC(4567);
Output
1
Testing a Numeric String
Checking if a string representing a number is numeric (it is!).
Syntax
SELECT ISNUMERIC('4567');
Output
1
Testing Non-Numeric Text
Checking if a text string is numeric (it's not!).
Syntax
SELECT ISNUMERIC('Hello world!');
Output
0
Testing a Numeric Expression
Checking if a simple calculation is numeric (it is!).
Syntax
SELECT ISNUMERIC(20 * 3);
Output
1
Testing a Date String
A date string is not considered numeric by `ISNUMERIC()`.
Syntax
SELECT ISNUMERIC('2017-08-25');
Output
0