Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 t-sql question

Author  Topic 

sqlserverdeveloper
Posting Yak Master

243 Posts

Posted - 2008-06-12 : 16:53:27
I am trying to do the following:
On running the query
select 59/60 - I am getting value as 0.
But actual 59/60 is 0.983333
I want the select 59/60 to return the actual value which is 0.983333, tried to convert that to int, decimal, float etc
but nothing worked, please let me know what I should do. Thanks!!

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2008-06-12 : 16:55:23
try this
select 59/60.0

Chirag

http://www.chirikworld.com
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-12 : 17:14:05
Check out data type precedence in SQL Server Books Online. In it, you'll see this:

quote:

When both operand expressions have the same data type, the result of the operation has that data type.



59/60 is int/int, so you'll get an int returned. It chopped off all of your decimal places.

59/60.0 is int/decimal, so you'll get a decimal returned due to data type precedence.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-13 : 01:09:50
There's also a blog of Madhi on this

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx
Go to Top of Page
   

- Advertisement -