Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Percentage Calculation 2

Status
Not open for further replies.

IAMINFO

MIS
Feb 21, 2002
62
US
Hello everyone,
I am trying to calculate the percentage.
ICount is what percentage of FaCount, I keep getting 0 in the percentage column, what am I doing wrong.

Thank you for reading this post


select * ,(ICount / FaCount) * 100 AS Percentage

from religionCounts


Facility ICount Religion FaCount Percentage
---------- ----------- -------------------- ------------- -----------
ASDCU 15 7-ADVENT 814 0
ASDCU 25 HEBREW 814 0
ASDCU 125 LUTHERAN 814 0
ASDCU 200 MUSLIM 814 0
 
cast(icount/nullif(Facount,0) * 100 as decimal(12,4)) as Percentage

Integer divided by integer will procude an integer, that's why you get wrong result. You must cast to the correct type.
 
markros has it right. You can also cheat...

select * , ICount * 100.0 / FaCount AS Percentage

--Jeff Moden
-------------------------------------------------------------------------------
"RBAR" is pronounced "ree-bar" and is a "Modenism" for "Row By Agonizing Row
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top