I want to get the percentage of acceptable, excellent, notacceptable, using the below query but the answer is repeating
begin
set nocount on
declare @acceptable as varchar(10)
declare @Excellent as varchar(10)
declare @NotAcceptable as varchar(10)
declare @total as varchar(10)
declare @percent1 as varchar(10) = null
declare @percent2 as varchar(10) = null
declare @percent3 as varchar(10) = null
select @acceptable = count(*)
from [dbo].[tbl_Apprisal]
where ApprisalStatus = 'Acceptable'
select @Excellent = count(*)
from [dbo].[tbl_Apprisal]
where ApprisalStatus = 'Excellent'
select @NotAcceptable = count(*)
from [dbo].[tbl_Apprisal]
where ApprisalStatus = 'Not Acceptable'
SET @total = convert(decimal, @acceptable) +
convert(decimal, @Excellent) +
convert(decimal, @NotAcceptable)
SET @percent1 = convert(int, @acceptable) * convert(int, 100) / convert(int, @total)
SET @percent2 = convert(int, @Excellent) * convert(int, 100) / convert(int, @total)
SET @percent3 = convert(int, @NotAcceptable) * convert(int, 100) / convert(int, @total)
select
'Accplable:' + @percent1 + '%' + ',' + 'Excellent:' + @percent2 + '%' + ',' + 'Not Acceptable:' + @percent3 + '%' as persnt,
Emp.personFname as doneby1,
Em.personFname + Em.[personMname] + Em.[personLname] as personFname1,
ap.ProcessId, ap.empNumber,
ap.fromDate ApprisalStatus, ap.comment, ap.DoneBy,
convert(date, ap.DoneByDate, 105) as DoneByDate
from
[dbo].[tbl_Apprisal] ap
inner join
[dbo].[tbl_EmployeePersonalDetails] Em on Em.empNumber = ap.empNumber
inner join
[dbo].[tbl_EmployeePersonalDetails] Emp on Emp.empNumber = ap.DoneBy
order by
convert(date, ap.fromDate, 105) DESC
In this SQL query the value is repeating please help me to solve it