DF041: The ISNUMERIC function is used.

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

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for SQL Server?