Base de connaissances

Percent Calculation Returns 0 Dividing Numbers

Hint Ref: 021003050001
Hint Date: 05/03/2010

Hint Details:

<pclass="hint_description">The following calculation returns 0:

 

select
23/26*100

Sybase is seeing two integers being divided and returning an integer as an answer. To get the percent calculation required:

select
23.0/26.0*100

As the following will not give the desired result:

select
count(*) as NumUnits,
sum(unitoccupied(unit.unitid)) as NumOcc,
NumOcc/NumUnits/100 as PercentOcc
from
unit join sizecodrate join sizecode

It needs to be:

select
cast(count(*) as NumUnits as float),
cast(sum(unitoccupied(unit.unitid)) as float) as NumOcc,
NumOcc/NumUnits/100 as PercentOcc
from
unit join sizecodrate join sizecode


(Please Note: This Procedure can be destructive and should only be used by Advanced Users.  RADical Systems (UK) Limited or its Partners cannot be held responsible, in anyway, for any consequence of using this or any other Database Function, Procedure or SQL command.  Responsibility resides solely with the user.  

IT IS HIGHLY RECOMMENDED THAT A FULL AND VALID SPACE MANAGER DATABASE BACKUP IS TAKEN AND VERIFIED AS VALID BEFORE MAKING ANY CHANGES TO THE DATABASE.)