DF041: The ISNUMERIC function is used.

Last modified: December 25, 2024

The topic describes the DF041 T-SQL code analysis rule.

Category

EXECUTION RULES

Message

The ISNUMERIC function is used.

Description

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.

Additional information

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.

Noncompliant code example

SELECT
  *
FROM dbo.DemoTable
WHERE ISNUMERIC(DataField) = 1

Compliant solution

SELECT
  *
FROM dbo.DemoTable
WHERE TRY_CAST(DataField AS INT) IS NOT NULL