Quantcast
Channel: Select query returns 0 for calculating percentage using division operator
Browsing latest articles
Browse All 4 View Live

Select query returns 0 for calculating percentage using division operator

Wrap the whole calculation in CAST with desired precision:SELECT CAST((group_total / CAST(total AS DECIMAL(10, 2))) * 100 AS DECIMAL(5, 2)) ... -- Plamen Ratchevhttp://www.SQLStudio.com

View Article



Select query returns 0 for calculating percentage using division operator

Great! I used CAST function and Now I am getting the percentage as 15.48876053How to round it to 15.49 ?Thanks.

View Article

Select query returns 0 for calculating percentage using division operator

This is because of the integer division. You can cast one of the operands to DECIMAL with correct precision, or simply do something like this:SELECT (group_total * 1.0/total) * 100 FROM...

View Article

Select query returns 0 for calculating percentage using division operator

When I do, select (group_total/total)*100 from transfer_out_summary;The rows are returning with 0 values.group_total has 12969 and total has 115973I am actually calculating percentage. How to correct...

View Article
Browsing latest articles
Browse All 4 View Live




Latest Images