我想在 where 子句中使用 case 语句,但在下面的查询中出现错误。
where
(r.WeekId=@WeekId or @WeekId is null) and
(ShiftId=@ShiftId or @ShiftId is null)
and (placeid=@PlaceId or @PlaceId is null)
and (r.StatusId=3)
AND
CASE WHEN @day = 1 THEN ((firstday=@time and (allocateddays is null or NOT (AllocatedDays LIKE '%1%'))))
WHEN @day = 2 THEN ((secondday=@time and (allocateddays is null or NOT (AllocatedDays LIKE '%2%'))))
WHEN @day = 3 THEN ((thirdday=@time and (allocateddays is null or NOT (AllocatedDays LIKE '%3%'))))
ELSE AND (1 = 1)
END
我在第行的 Case 语句中遇到错误 CASE WHEN @day = 1
。我的查询出了什么问题。请帮忙。