• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 61
  • Last Modified:

ISNUMERIC logic stopped working


In a stored procedure we have a query that has worked in the past but no longer does on after we upgraded servers. The new server is SS2016.  It still works on our older 2012SQL Server.  Any type of options / settings that may have been that jump out at you? Or any reason at all whey we are suddenly encountering this.

Older version:

        AND ISNUMERIC(drug.GCN_SEQNO) > 0

Note: the data  from g.GCN_SEQNO is all numeric. The data in the drug.GCN_SEQNO is a char field because it has one value = 'UNKNOWN'. The rest of the data is numeric format.

When we changed to a CASE statement or Try_cast, it works fine. So we solved for it, but just not sure why its not an issue.
Updated versionL

WHERE g.GCN_SEQNO = try_cast(drug.GCN_SEQNO as numeric(28,0))
  • 2
1 Solution
Mark WillsTopic AdvisorCommented:
Unfortunately, comparing that way wont work

I believe the database engine looks at predicates individually if part of an index, so would be looking at the '=' and is pretty pedantic about char v number

As you have discovered, you can do
WHERE g.GCN_SEQNO = try_cast(drug.GCN_SEQNO as numeric(28,0))

Open in new window

Scott PletcherSenior DBACommented:
SQL can execute WHERE conditions in any order.  In 2012, it seems that SQL was always doing the ISNUMERIC() first, which makes sense logically as well.  But 2016 may not set the same priority for that.  Note that if SQL tries the = condition first, and the drug. column is not valid, you would get a conversion error.
Mark WillsTopic AdvisorCommented:
I have been doing a bit of digging, and struggling to find any precedence.

If you were to grab the execution plan and analyse the plan I am pretty sure you will find the "=" being evaluated before the ISNUMERIC

So, execution plans have probably changed since upgrade. Have there been any structural changes to tables ? reindexing ?
jvoconnellAuthor Commented:
Thank you all for the input.

Comparing execution plans did help. After investigation it looks like changes to the object was made without all of the necessary communication. We sincerely appreciate the effort. Thank you!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now