Solved

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

Posted on 2014-07-17
2
142 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now