SQL Conversion failed when converting the nvarchar value '3.00' to data type int.

Getting error:  Conversion failed when converting the nvarchar value '3.00' to data type int.

on Field LeadTime. I've tried Cast and Convet and both fail.
SELECT MPN, InternalPN, CONVERT(INT, LeadTimeMin) FROM AustinFullExportTemp WHERE MPN = 'xxxxx'

Open in new window

LVL 2
CipherISAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

irudykCommented:
Try:
SELECT MPN, InternalPN, CAST(LeadTimeMin AS NUMERIC(10,2)) FROM AustinFullExportTemp WHERE MPN = 'xxxxx'

Open in new window

If use the above I get a value back of '3.00'
If the text value was '3.75' I'd get 3.75
You indicated that you want the int value which is 3 for '3.00' and 3 for '3.75'
If I were to change numeric(10,2) to numeric(10,0) the results would not be correct as it would give 3 for '3.00' and 4 for '3.75'

So, I would then change the code to:
SELECT MPN, InternalPN, CONVERT(INT,CAST(LeadTimeMin AS NUMERIC(10,2))) FROM AustinFullExportTemp WHERE MPN = 'xxxxx'

Open in new window


Someone else might have a cleaner way to accomplish this, but the above should work for you.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CipherISAuthor Commented:
Thanks!!!
irudykCommented:
Also, just in case the value in the field is not always numeric text you could use
SELECT MPN, InternalPN, CASE WHEN ISNUMERIC(LeadTimeMin) = 1 THEN CONVERT(INT,CAST(LeadTimeMin AS NUMERIC(10,2))) ELSE 0 END FROM AustinFullExportTemp WHERE MPN = 'xxxxx'

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.