我有以下代码
DECLARE @ProjectID INT
DECLARE @getSLAPrjectID CURSOR
SET @getSLAPrjectID = CURSOR FOR SELECT ProjectID FROM SLA
OPEN @getSLAPrjectID
FETCH NEXT
FROM @getSLAPrjectID INTO @ProjectID
WHILE @@FETCH_STATUS = 0
BEGIN
BEGIN
SET @ScheduleVariance = (select case when (DATEDIFF(day,PlannedStartDate,PlannedEndDate)=0) THEN 0 ELSE (DATEDIFF(day,ActualStartDate,ActualEndDate)-DATEDIFF(day,PlannedStartDate,PlannedEndDate))/CAST(DATEDIFF(day,PlannedStartDate,PlannedEndDate) as float) END from SLA)
-- other piece of code that is working fine
END
FETCH NEXT
FROM @getSLAPrjectID INTO @ProjectID
END
CLOSE @getSLAPrjectID
DEALLOCATE @getSLAPrjectID
--end
我收到以下错误:子查询返回超过 1 个值。当子查询跟随 =、!=、<、<=、>、>= 或子查询用作表达式时,这是不允许的。
请让我知道在这段代码中是否有任何替代 CASE 语句或替代标量变量的方法。