[英]Find Date falls within Range
We have a table containing 4 columns 我们有一个包含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
I want to write a query which will return true or false based on if a particular date falls within startDate and EndDate of a particular Employee 我想编写一个查询,该查询将基于特定日期是否在特定Employee的startDate和EndDate内而返回true或false
Example if we pass empID 223 and date 2014-08-13 the query should return true but if we pass empID 223 and date 2014-08-23 the query should return false 例如,如果我们传递empID 223和日期2014-08-13,则查询应返回true,但如果我们传递empID 223和日期2014-08-23,则查询应返回false
How can I do that? 我怎样才能做到这一点?
SQL Server doesn't have "true" and "false" built in. You can return 0/1 like this: 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;
SELECT CASE WHEN
empID = 223 AND '2014-08-23' BETWEEN StartDate AND EndDate
THEN 'true'
ELSE 'false'
END FROM data;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.