DEV Community

Tino Joel Muchenje
Tino Joel Muchenje

Posted on

1

How to find non-numeric values in SQL Server

Have you ever encountered an error like this when trying to convert a varchar column to a numeric column in SQL Server?

Error converting data type varchar to numeric

This error occurs when the varchar column contains some values that are not valid for the numeric data type, such as alphabets, symbols, spaces, commas, etc.

In this article, I will show you how to find these non-numeric values using some simple SQL queries.

Finding non-numeric values

There are two main ways to find non-numeric values in a varchar column in SQL Server. One way is to use the ISNUMERIC() function, which returns 1 for numeric values and 0 for non-numeric values. Another way is to use the LIKE operator with a pattern that matches any character that is not a digit.

For example, suppose we have a table called Payments with a column called Amount that contains some varchar values. Some of them are numeric, some of them are not. Here is a sample of the data:

Amount
100.00
50.00
75.00
80
90.00
AB
ABCDE#
.ABC

To find the non-numeric values using the ISNUMERIC() function, we can use this query:

Select Amount
from Payments
where ISNUMERIC(Amount) <> 1

This will return the following rows:

Amount
AB
ABCDE#
.ABC

To find the non-numeric values using the LIKE operator, we can use this query:

Select Amount
from Payments
where Amount like '%[^0-9]%'

This will return the same rows as before:

Amount
AB
ABCDE#
.ABC

Conclusion

In this article, I have shown you how to find non-numeric values in a varchar column in SQL Server using some simple SQL queries. I hope this helps you understand the cause of the error Error converting data type varchar to numeric and prepare your data for conversion.

If you have any questions or feedback, please let me know in the comments below.

Happy coding!

Image of PulumiUP 2025

Explore What’s Next in DevOps, IaC, and Security

Join us for demos, and learn trends, best practices, and lessons learned in Platform Engineering & DevOps, Cloud and IaC, and Security.

Save Your Spot

Top comments (0)

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay