我们有一个包含4列的表格
Column 1: ID
column 2:EmpID
Column 3:startDate
Column 4:EndDate
DATA
ID EMPID StartDate EndDate
1 223 2014-06-06 2014-06-10
2 223 2014-08-11 2014-08-22
1 224 2014-09-06 2014-09-10
2 224 2014-12-11 2014-12-22
我想编写一个查询,该查询将基于特定日期是否在特定Employee的startDate和EndDate内而返回true或false
例如,如果我们传递empID 223和日期2014-08-13,则查询应返回true,但如果我们传递empID 223和日期2014-08-23,则查询应返回false
我怎样才能做到这一点?
SQL Server没有内置的“ true”和“ false”。您可以返回0/1,如下所示:
select (case when count(*) > 0 then 1 else 0 end) as TrueIs1
from t
where empId = @empId and
@date between StartDate and EndDate;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句