Solved

SQL - convert txt to int and calculate (where some values are null)

Posted on 2014-07-17
2
146 Views
Last Modified: 2014-07-17
I've some numbers stored as txt and need to handle nulls while also doing a calculation.

AND CAST(ISNULL(MED_PVAR1_DPD,'0') AS INT) < 3.05

despite my thinking this might work the above gives me :
"Conversion failed when converting the varchar value '3.05' to data type int."
0
Comment
Question by:ghettocounselor
2 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 40203166
My quick guess would be that casting a varchar that contains a decimal point to an integer is not allowed. Have you tried casting it to a decimal?
0
 

Author Closing Comment

by:ghettocounselor
ID: 40203332
AND CAST(ISNULL(MED_PVAR1_DPD,'0') AS DECIMAL) < 3.05

THIS WORKED !
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question