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)
 Why am i getting zero

Author  Topic 

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2009-12-22 : 23:32:13
hi

I tried executing the TSQL code but am getting zero when it should be 0.10. Why is it so? Thanks

Declare @Discount as decimal(18,2)
Set @Discount = 10/100
Select @Discount

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-12-22 : 23:37:14
integer divide by integer will give you the result in integer


Declare @Discount as decimal(18,2)
Set @Discount = 10.0/100
Select @Discount



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-12-23 : 00:32:51
This too will solve your issue

Declare @Discount as decimal(18,2)
Set @Discount = 10/100.0
Select @Discount

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-23 : 01:16:47
Read this to know the reason
http://sqlblogcasts.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 -