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 2008 Forums
 Transact-SQL (2008)
 Decimal not displaying

Author  Topic 

baguhan
Starting Member

3 Posts

Posted - 2011-01-24 : 06:11:36
can somebody help me how can i display the decimal no. on this script?


declare @x decimal(5,2)
select @x=(1*9)/24
select @x

result is : 0.00

on calculator the result is : 0.375

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-01-24 : 07:24:48
In SQL Server, an integer divided by an integer is an integer, so .375 becomes 0.00.


declare @x decimal(5,2)
select @x=(1.0*9)/24 -- turns the integer into a numeric
select @x

Jim


Everyday I learn something that somebody else already knew
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-01-24 : 07:40:25
Also refer this post
http://beyondrelational.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -