【发布时间】:2021-03-14 21:14:27
【问题描述】:
您好,由于我的代码错误,我遗漏了一些东西。
select * from ##ScheduleDetail SD
left join ##HolidayFilterTbl HF on SD.Scheduledate = HF.Testdate
where (ScheduleDate = testdate)
and
(Case
when HF.IsHoliday = 1 then (overtime = 1 and makeup = 0)
else
(overtime = 0 and Makeup = 0)
end
)
and
DOW = 5
order by ActivityStartTime
我尝试了几种组合,每个组合都在第一个等号或第二个等号处出错。我错过了什么?
【问题讨论】:
-
跳过 case 表达式尝试,改用 AND/OR。
-
CASE表达式必须生成单个值,而不是要计算的附加代码。 -
@JoelCoehoorn,
(overtime = 1 and makeup = 0)返回 TRUE/FALSE/null。 -
用您正在使用的数据库标记您的问题。
标签: sql select where-clause case-statement