SQLSERVER语句怎么查询一个时间段的数据

如题所述

select * from 表 where 日期字段>='开始日期' and 日期字段<='截止日期'
and convert(char(8),日期字段,108)>='开始时间' and convert(char(8),日期字段,108)<='截止时间'

例如:
select * from tb1 where dDate>='2010-11-05' and dDate<='2010-11-15'
and convert(char(8),dDate,108)>='22:30:00' and convert(char(8),dDate,108)<='23:00:00'
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-04-17

使用datename函数来取时间中分钟的值,因为整点,都是0分钟。

date表示字段

select * from table where date between '2016-10-01' and '2017-10-01'

或者


select * from table where date>'2016-10-01' and date<'2017-10-01'
两个区别不大,between包含了两头的日期,那个不包含。

本回答被网友采纳