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
 General SQL Server Forums
 New to SQL Server Programming
 1/100 = 0 ???

Author  Topic 

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-09-21 : 01:03:25
Dear Friends,

when i run query in sql server as follows:
select (1/100) the result is 0, where as i want 0.01

How could i achieve this ?

Many Thanks,
Amodi

No paiN No gaiN

Ancy
Starting Member

23 Posts

Posted - 2010-09-21 : 01:08:00
select convert(numeric,1)/100
Go to Top of Page

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-09-21 : 01:09:54
Thanks a Million for your quick reply.

No paiN No gaiN
Go to Top of Page

Ancy
Starting Member

23 Posts

Posted - 2010-09-21 : 01:12:02
You are welcome :)
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-09-21 : 01:13:09
Try this

select (1/100.0)

The dividend must be a float !

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

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

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-09-21 : 01:14:15
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

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

Subscribe to my blog
Go to Top of Page

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-09-21 : 01:41:53
Thank you all.

No paiN No gaiN
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-09-21 : 07:22:54
quote:
The dividend must be a float !
Not necessarily, it just needs to support decimal values:
declare @m money, @n numeric(10,2)
select @m=12, @n=12
select 1/@m, 1/@n, 1/12e -- E suffix denotes numeric type

Go to Top of Page
   

- Advertisement -