我想在游标中执行以下操作。 是否可以只使用一个案例来分配多个值?
CASE
when @region = ‘Region 1’ then @sum_region1 = @sum_region1 + @sum_actual
when @region = ‘Region 2’ then @sum_region2 = @sum_region2 + @sum_actual
when @region = ‘Region 3’ then @sum_region3 = @sum_region3 + @sum_actual
when @region = ‘Region 4’ then @sum_region4 = @sum_region4 + @sum_actual
End
答案 0 :(得分:0)
尝试这样的事情:
IF @region = 'Region 1'
BEGIN
SET @sum_region1 = @sum_region1 + @sum_actual
END
IF @region = 'Region 2'
BEGIN
SET @sum_region2 = @sum_region2 + @sum_actual
END
IF @region = 'Region 3'
BEGIN
SET @sum_region3 = @sum_region3 + @sum_actual
END
IF @region = 'Region 4'
BEGIN
SET @sum_region4 = @sum_region4 + @sum_actual
END