Error converting data type varchar to numeric where ISNUMERIC finds only numbers

I am writing some SQL to form the basis of views to pull data from a Microsoft SQL Server source into Azure SQL Database, and then the data would go to Power BI. The data was all presented in string format initially (not my data, not my monkeys, not my circus), and I wanted to correct the data types before the data got into Power BI.

I noted that one of the columns failed to convert VARCHAR to DECIMAL. The error message is below, and it’s usually fairly easy to sort:

Error converting data type varchar to numeric

Normally, I’d use ISNUMERIC to identify the rows that fail to have a value in that column that could be converted to a number. Then, I could identify the value, and then I could replace or exclude it, as required.

However, on this occasion, using ISNUMERIC failed to identify any columns as being non-numeric. ISNUMERIC returned all of the rows as TRUE, and that confused me. I knew that something was triggering the CONVERT instruction to go wrong.

parrot-1070624_1920
Confused? yes, me too. Credit: https://pixabay.com/en/users/lovelikeahurricane-720440/

I ran a quick query, ordering the column in ASCENDING order, while running the original offending query that failed. This showed that the query stopped at the value 9.45. I then ran another query that returned the rows, where the value was greater than 9.45, and ordered the results.

In this result set, the value came through as follows:

9.450000001e-05

Aha! This explained why SQL Server could convert the value to numeric, because of the scientific notation used when the values are very large or very small.

Now, I ran my query again, using a NOT LIKE (which I also do not like!)

WHERE [My Column Name] NOT LIKE ‘%e%’
Now, out of my large record set, I got one offending row with the scientific notation, out of millions of rows. At least I had something to work with now; I could remove the data, run an update, or work with the scientific notation.
I hope that helps someone!
Share the Post:

Related Posts

Is Your Power BI a Spotlight or an Instagram Filter?

Power BI’s greatest value might not be the insights it delivers. Rather than masking the issues like an Instagram filter, Power BI may be your critical friend because of the problems it exposes. The wise thing to do is to use that signal to navigate your next step, rather than try to mask it as if it is an Insta filter. 

Read More

When Trusted Domains Betray Trust: Power BI Scam-Spam and the Case for Proactive BI Governance

Microsoft Power BI is facing increased phishing attacks that exploit its legitimate report subscription feature, allowing scammers to send malicious emails from trusted domains. Organisations need to recognise that Business Intelligence tools have functionality that could be used for good or bad. Governance means understanding the features, and using controls that recognise the fine line between business intelligence and cybersecurity.

Read More

From Pipes to Intelligence: Why Microsoft's FY25 Q2 Earnings Signal a New Era for AI ROI

Microsoft’s latest earnings call indicates a strategic shift towards prioritizing high-margin AI software over infrastructure. With 15 million Copilot users, the focus is on transforming enterprise value through active user engagement rather than mere license purchases. The emphasis on intelligence signals the future direction for organizations investing in AI.

Read More

Discover more from Jennifer Stirrup: AI Strategy, Data Consulting & BI Expert | Keynote Speaker

Subscribe now to keep reading and get access to the full archive.

Continue reading