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
。私のクエリで何が問題になっていますか。助けてください。