Percentage Calculation with two decimal digit rounded off

  • Hi,

    I am using the following query to find the top 10 transaction and percentage of transaction which is giving percentage in integer only. I tried with 100.0 in stead of 100 which is giving 16.466666666666%. But i want percentage like 16.47%, 13.33%. Any Help please

    SELECT TOP 10 DFS_Request_Received as trans,((DFS_Request_Received*100)/(case Total.totalTrans when 0 then 1 else Total.totalTrans end)) as Percentage

    FROM DFS,

    (select sum(DFS_request_received) as totalTrans from DFS) Total

    order by trans desc

  • Try this...

    SELECT TOP 10 DFS_Request_Received as trans

    ,ROUND(((DFS_Request_Received*100.0)

    /(case Total.totalTrans when 0 then 1 else Total.totalTrans end)),2) as Percentage

    FROM DFS,

    (select sum(DFS_request_received) as totalTrans from DFS) Total

    order by trans desc

  • Hi

    select (1*100)/9 which will give the result as 11

    select (1*100.0)/9 which will give the result as 11.111111

    select round(((1*100.0)/9),2) which will give the result as 11.110000

    but i want the result as 11.11 only

    How to remove the trailing zeros? Any suggestion?

  • select cast(round(((1*100.0)/9),2) as decimal(5,2))

  • Hi

    Thank you. CAST function worked for me

    Latha

  • Hi

    select 100*(24698891)/39552506

    i need answer 62.44

    How can i reach the requirement? Any suggestion?

    Thanks in advance

  • Karthik wrote:

    Hi select 100*(24698891)/39552506 i need answer 62.44 How can i reach the requirement? Any suggestion? Thanks in advance

    select convert(decimal(9,2),100*(convert(decimal(15,4),24698891))/convert(decimal(15,4),39552506)) Percentage

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply