Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I want to calculate percentage. The given below query showing the percentage properly. But the output is like 34.3452344. I need to reduce fraction as 34.345. How can I modify the given below query. help me to find a proper solution. Thank you.
SQL
SELECT SlNo, SiteID, OnTime, DueTime, (OnTime * 100.0) / NULLIF (Max(OnTime) OVER (), 0) Percentage1, (DueTime * 100.0) / NULLIF (Max(OnTime) OVER (), 0) Percentage2
FROM  tbl_Per
Posted

 
Share this answer
 
Comments
Member 11042100 20-Jan-15 3:41am    
@Abhinav S :Can you modify the above query using round method.
Abhinav S 20-Jan-15 4:52am    
Try on your own and post the query here if you still run into problems.
Seems you are using MS SQL SERVER
try the STR[^] function
 
Share this answer
 
You could try convert, something like this:
SQL
--data setup
declare @percent numeric(12,8);
set @percent = 34.3452344;
--query
select convert(decimal(12,3), @percent) percentage;
--result
--34.345
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900