Skip to content Skip to sidebar Skip to footer

How To Accurately Figure Percentage Of A Finite Total

I’m in the process of creating a report that will tell end users what percentage of a gridview (the total number of records is a finite number) has been completed in a given mont

Solution 1:

The following query should provide what you are looking for:

Declare@DivNumberdecimal(5,1);

SET@DivNumber= (.01*2541);

SELECTCAST(ROUND(@DivNumber/Count(date_record_entered), 1) ASdecimal(5,1))
  FROM dbo.tablename 
 WHERE date_record_entered ISNOTNULLand date_record_entered >=20131201AND date_record_entered <=20131231

Solution 2:

Why do you select the constant value cast(round(@divNumber / @DateCount, 1) as decimal(5,1)from the table? That's the cause of your problem. I'm not too familiar with sql server, but you might try to just select without a from clause.

Solution 3:

select emp.Natinality_Id,mstn.Title as Nationality,count(emp.Employee_Id) as Employee_Count,
count(emp.Employee_Id)*100.0/nullif(sum(count(*)) over(),0)  as Nationality_Percentage
FROM Employee as emp
leftjoin Mst_Natinality as mstn on mstn.Natinality_Id = emp.Natinality_Id
where
emp.Is_Deleted='false'groupby emp.Natinality_Id,mstn.Title

Post a Comment for "How To Accurately Figure Percentage Of A Finite Total"