Get the percentage as a whole number

sanjshah12
sanjshah12 used Ask the Experts™
on
Hi,

I am trying to return the percentage a single figure

declare @countOfAll INT
select @countOfAll = COUNT(*) from tbl_QuizDetails

declare @Type1 INT
select @Type1= COUNT(*) from tbl_QuizDetails WHERE QuizType='Type1'

SELECT (@Type1 /@countOfAll)*100 AS Type1

Open in new window


However, the returned value is 0 although I have checked the values Type1=1812 and CountOfAll=3242

Am I doing something wrong to return the value as 56?

Regards,
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior DBA
Most Valuable Expert 2018
Top Expert 2014
Commented:
SELECT CAST((@Type1* 1.0 /@countOfAll)*100 AS int) AS Type1
Doug BishopDatabase Developer
Commented:
Change SELECT (@Type1 /@countOfAll)*100 AS Type1
to
SELECT (@Type1 * 1.0 /@countOfAll)*100 AS Type1
to display as a whole number
SELECT CAST((@Type1 * 1.0 /@countOfAll)*100 AS DECIMAL(10,0)) AS Type1
NorieAnalyst Assistant
Commented:
Try this.

SELECT (@Type1 * 100.0 /@countOfAll) AS Type1

Author

Commented:
Many thanks guys.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial