The topic describes the DF041 T-SQL code analysis rule.
EXECUTION RULES
The ISNUMERIC function is used.
Avoid using the ISNUMERIC function as it accepts floating point and monetary number formats, does not distinguish between data types, and may report an unexpected result.
The ISNUMERIC function returns true for a wide range of data types, including numeric, currency, and even some non-numeric characters like ‘+’, ‘-‘, and ‘.’. This can lead to ambiguity in the results, especially if you’re expecting only integer or decimal values.
Additionally, the ISNUMERIC function does not provide information about the precision or scale of numeric values. It treats all numeric values as equal, whether they are integers, decimals, or floating-point numbers.
Using ISNUMERIC can lead to poor performance, especially when applied to large datasets. This function has to evaluate each character in the input string to determine if it represents a numeric value, which can be resource-intensive.
SELECT
*
FROM dbo.DemoTable
WHERE ISNUMERIC(DataField) = 1
SELECT
*
FROM dbo.DemoTable
WHERE TRY_CAST(DataField AS INT) IS NOT NULL