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)
 Get Decimal Value

Author  Topic 

gksharma
Starting Member

11 Posts

Posted - 2007-08-22 : 02:35:46
select convert(decimal(5,2),(7058/7482)*100 ,0) is shwoing me .00 value instead of 94.33. How to resolve it.
Thanks & Regards

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-22 : 02:51:01
select convert(decimal(5,2),(7058/7482.0)*100 ,0)

See what the major change is

Madhivanan

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

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2007-08-22 : 02:53:02
try this..
select (7058.00/7482.00)*100
Go to Top of Page

gksharma
Starting Member

11 Posts

Posted - 2007-08-22 : 03:40:44
Yes, these are running; but my basic query is something like this :
select a.area,a.total,b.pass from (select area,count(*) as total from mytable group by area) a,
(select area,count(*) as pass from mytable where (result='1ST' or result='2ND') group by area) b
where a.area=b.area
order by a.area

Now i want to create one more column here showing percentage of pass candidate i.e. based on pass/total*100

Thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-22 : 04:20:20
Try

select a.area,a.total,b.pass,1.0*b.pass/a.total*100 as percentage from (select area,count(*) as total from mytable group by area) a,
(select area,count(*) as pass from mytable where (result='1ST' or result='2ND') group by area) b
where a.area=b.area
order by a.area


Madhivanan

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

gksharma
Starting Member

11 Posts

Posted - 2007-08-22 : 05:51:04
Thank You Madhivanan....!
This bit help resolved my big problem...!
Thanks Again
Regards
Girish
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-22 : 06:35:41
quote:
Originally posted by gksharma

Thank You Madhivanan....!
This bit help resolved my big problem...!
Thanks Again
Regards
Girish



Well. You need to be careful when you divide two integers. To get accurate result you need to multiply it by 1.0

Madhivanan

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

- Advertisement -