We help IT Professionals succeed at work.
Get Started

Compare a numeric value to a varchar w/o getting an error

Last Modified: 2017-03-15
I have the following query

      select si.OrderID, SO.ORDERDATE, QtyOrdered
, si.LineCost, si.ProductDesc, si.BrandID, SI.CaseSellingPrice
      fROM SAMSDW.storis.OrderItem SI                                                
      JOIN SAMSDW.storis.Orders SO ON
            SO.OrderID = SI.OrderID
      WHERE SI.OrderID = '300119'
      and si.ProductID not in (select itemid from INVENTORY where itemid = CASE WHEN ISNUMERIC(SI.PRODUCTID) = 1 THEN CONVERT(NUMERIC(18,0), SI.PRODUCTID) ELSE 0 END)

ITEMID is a numeric(18,0) in INVENTORY and PRODUCTID is varchar(50) in SAMSDW.  Sometimes, the SAMSDW table will be a number, most of time it will not.  I merely want to test the 2 values by converting/casting the PRODUCTID if it's numeric.  But I crash no matter what.

Is there any way to get around the error?

Watch Question
Database Consultant
Top Expert 2009
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE