5 replies

Last post Jun 10, 2015 08:44 AM by eralper

Member

27 Points

181 Posts

calculate percentage

select occupied,available from hotel;

they are float.

Ex: If I have 529578 and 529578. I should be able to get as 100%

percentage

Contributor

5450 Points

1123 Posts

Re: calculate percentage

I do not know if I understand correctly but try:

```select
occupied,
available ,
occupied / available * 100 as Percentage
from hotel```

Hope this helps.

percentage

Star

8536 Points

1376 Posts

Microsoft

Re: calculate percentage

Jun 09, 2015 02:08 AM|Edwin Guru Singh|LINK

sushsudh

Ex: If I have 529578 and 529578. I should be able to get as 100%

According to the given example, its unclear.
What is the meaning of 529578 ?
you want to try like below :

`select occupied,available,CASE WHEN  available=occupied then '100%'Else 'Not 100%'END [Status]from hotel`

If I misunderstood ,kindly explain your expected result clearly.

percentage

with regards,
Edwin

Member

594 Points

386 Posts

Re: calculate percentage

```select
convert(varchar, (occupied/529578)*100)+'%' as occupied ,
convert(varchar, (available /529578)*100)+'%' as available

from hotel```

percentage

Help to each other

Contributor

6248 Points

5408 Posts

Re: calculate percentage

Try

`select ltrim(rtrim(cast(cast(round(529578/529578) as int) as varchar))) + "%"`

percentage

Many Thanks & Best Regards,
HuaMin Chen

Contributor

5961 Points

1411 Posts

Re: calculate percentage

Hello,

You can check the available amount to prevent errors

```select *,
convert (varchar(100),
case available
when 0 then 0
else
100 * occupied / available
end) + '%' Percentage,
convert (varchar(100),
convert(decimal(18,2),
case available
when 0 then 0.00
else
100.00 * occupied / available
end)) + '%' PercentageDecimal
from hotel```

I also added second column for percentage calculation in decimal up to 2 decimals

percentage