У меня проблемы с попыткой вычислить промежуточную сумму из оператора CASE.У меня есть две таблицы @report
и @question
и две переменные @countCurrent
и @countSuggested
.
На основе чисел в таблице @report
по сравнению со статическим значением или значением из *Таблица 1008 * Мне нужно увеличить либо @countCurrent
, либо @countSuggested
.
Вот то, что у меня есть, но вместо того, чтобы получить некоторую комбинацию 5 в каждом столбце, я получаю только 0/1.Я думаю, что это часть JOIN, но я не вижу, что.
declare @MinSuccessRate float,
@countCurrent int,
@countSuggested int
declare @report table
(
intID int identity(1,1),
intReportID int,
intParticipantID int,
acceptable float,
optimum float
)
insert @report
select 1,1,.25,.75 union all
select 1,2,.45,.75 union all
select 1,3,.35,.75 union all
select 1,4,.55,.75 union all
select 1,5,.65,.75
declare @question table
(
intID int identity(1,1),
intParticipantID int,
answer float
)
insert @question
select 1,35 union all
select 1,55 union all
select 1,65 union all
select 1,75 union all
select 1,85
SET @MinSuccessRate=0.75
SET @countCurrent=0
SET @countSuggested=0
UPDATE @report
SET @countCurrent=
CASE WHEN acceptable>=@MinSuccessRate
THEN @countCurrent+1
ELSE 0
END,
@countSuggested=
CASE WHEN optimum*100 >=q.answer
THEN @countSuggested+1
ELSE 0
END
FROM @report pr
INNER JOIN @question q
ON pr.intParticipantID=q.intParticipantID
WHERE pr.intReportID=1
select @countCurrent [Current],@countSuggested [Suggested]
Заранее спасибо!