[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

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

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
ghettocounselor
Asked:
ghettocounselor
1 Solution
 
Shaun KlineLead Software EngineerCommented:
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
 
ghettocounselorPharmacy Systems AdminAuthor Commented:
AND CAST(ISNULL(MED_PVAR1_DPD,'0') AS DECIMAL) < 3.05

THIS WORKED !
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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