Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL - CAST to two decimal places not working as expexted

Posted on 2014-04-18
2
Medium Priority
?
342 Views
Last Modified: 2014-04-18
I would expect that this:
CASE WHEN [ROUTE] IN ('PO','TOP','INH','TP','VAG') THEN CAST(MED_PRICE AS DECIMAL(18,2)) ELSE IV_PRICE END PT_CHARGE_BY_DU

would not give me 96.8800
but alas it does
0
Comment
Question by:ghettocounselor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
Alex Matzinger earned 2000 total points
ID: 40009751
What database are you using?  

is it possible that the 96.880 is not in  ('PO','TOP','INH','TP','VAG') so it is not being cast to a decimal?

Try this:

CASE WHEN [ROUTE] IN ('PO','TOP','INH','TP','VAG')
   THEN CAST(MED_PRICE AS DECIMAL(18,2))
   ELSE CAST(IV_PRICE AS DECIMAL(18,2)) END PT_CHARGE_BY_DU

And see what happens
0
 

Author Closing Comment

by:ghettocounselor
ID: 40009761
Thanks for the quick response.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

618 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