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 2000 Forums
 Transact-SQL (2000)
 Calculating a result using cast

Author  Topic 

eurob
Posting Yak Master

100 Posts

Posted - 2006-02-22 : 12:12:16
When I try to do this calculation:

select cast(15969 /2045595 as decimal(5,2))

I get .00

I tried it with decimal(38,2).. still the same.
Is there a way to calculate the correct result ?



robert

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-22 : 12:25:32
the result of dividing the 2 integer will be an integer. So you got 0 first before converting to 0.00.
Try
select cast(15969.0 /2045595 as decimal(5,2)) 


----------------------------------
'KH'

It is inevitable
Go to Top of Page

eurob
Posting Yak Master

100 Posts

Posted - 2006-02-22 : 12:54:07
Thanks, it worked.

robert
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-23 : 02:18:27
If you use variables, then just multiply it by 1.0


Declare @val1 int
Declare @val2 int
set @val1=15969
set @val2=2045595

select cast(@val1*1.0 /@val2 as decimal(5,2))


Madhivanan

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

eurob
Posting Yak Master

100 Posts

Posted - 2006-02-23 : 10:44:31
Thanks.

robert
Go to Top of Page
   

- Advertisement -