Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

cast function Expand / Collapse
Author
Message
Posted Friday, May 10, 2013 12:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, August 1, 2013 11:40 AM
Points: 5, Visits: 23
Ok, I know this is a silly question, but when I execute this code, it returns 1.00; however 3/2 really should be 1.50. What am I doing wrong here?

select cast (3/2 as decimal (5,2)) as 'test'
Post #1451426
Posted Friday, May 10, 2013 1:34 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 12:41 AM
Points: 3,030, Visits: 3,229
You're dividing an integer by an integer, which will return an integer (no decimal places), then the conversion to decimal takes place. Try:-

select cast (3/2.0 as decimal (5,2)) as 'test'

and you get 1.5


-------------------------------
Posting Data Etiquette - Jeff Moden
Smart way to ask a question

There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
I would never join a club that would allow me as a member - Groucho Marx
Post #1451447
Posted Friday, May 10, 2013 9:30 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, August 1, 2013 11:40 AM
Points: 5, Visits: 23
oh I see, that makes sense.
Thank you so much, I learned something new today!!
Post #1451644
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse