简体   繁体   English

查找日期在范围内

[英]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.

相关问题 计算在日期/时间范围内超出数据集的总时间 - Calculating total time that falls outside of dataset within date/time range Oracle SQL-确定时间戳是否在一个范围内,不包括日期 - Oracle SQL - Determine if a timestamp falls within a range, excluding date 在 Bigquery 表中查找每行所在的范围 - Find the range where each row falls within on a Bigquery table 在 SQL 中,如果日期范围在日期范围内,您能否编写 where 子句 - In SQL, can you write a where clause, if a date range falls within a date range SQL - 标记日期是否在 select 案例语句的日期范围内? - SQL - flag if a date falls within a date range within a select case statement? 如果表 2 中的日期值在表 1 中找到的日期范围内,则从表 2 中获取日期值或不可用 - Get date value or Unavailable from Table 2, if date value from Table 2 falls within a date range found in Table 1 如何过滤出今天日期在计算日期范围内的对象? - How can I filter out objects where todays date falls within a range of a calculated date? SQL根据另一个表中的日期范围查找日期在表中的位置 - SQL Find Where Date Falls in Table Based on Date Range in Another Table 如果当前值在日期范围内,则MS ACCESS Update列为空 - MS ACCESS Update column to null if current value falls within date range SQL查询按日期范围查找两个日期之间的所有数据 - SQL query to find all Data by date range which falls between two dates
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM