Я хочу, чтобы получить процент приемлемых, отлично, notacceptable, используя приведенный ниже запрос, но ответ повторяетПолучение значения SQL запроса повторение
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
В SQL запросе значения повторяющийся пожалуйста, помогите мне решить его
Какое значение повторяется? Какова ценность, которую вы видите, и чем вы ее оцениваете? –
, если вы используете триггер или proc .... добавьте эту строку SET NOCOUNT Off https://msdn.microsoft.com/en-us/library/ms189837.aspx –
Объедините подсчеты в [один выбор, используя регистр] (http://stackoverflow.com/questions/1400078/is-it-possible-to-specify-condition-in-count), чтобы избежать чтения таблицы три раза. –