从sqlserver中按时间段查询,比如控件时间范围1:20:30-5:20:06(注意:不是查询日期,查询日期用这个句子可以查,但是查询时间用这个句子就不行了)
shi = "时间 between '" + Str(DTPicker3.Value) + "' and '" + Str(DTPicker4.Value) + "'"
shi = "时间 between '" + Str(DTPicker3.Value) + "' and '" + Str(DTPicker4.Value) + "'"
tryshi = "时间 between '" + Str(format(DTPicker3.Value,"hh:mm:ss")) + "' and '" + Str(format(DTPicker4.Value,"hh:mm:ss")) + "'"
insert into @test
select '2009-12-14 0:0:0' union all
select '2009-12-14 1:0:0' union all
select '2009-12-14 2:0:0' union all
select '2009-12-14 3:0:0' union all
select '2009-12-14 4:0:0' union all
select '2009-12-14 5:0:0' union all
select '2009-12-14 6:0:0' union all
select '2009-12-14 7:0:0' union all
select '2009-12-14 8:0:0' union all
select '2009-12-14 9:0:0' union all
select '2009-12-14 10:0:0' union all
select '2009-12-14 11:0:0' union all
select '2009-12-14 12:0:0' union all
select '2009-12-14 13:0:0' union all
select '2009-12-14 14:0:0' union all
select '2009-12-14 15:0:0' union all
select '2009-12-14 16:0:0' union all
select '2009-12-14 17:0:0' union all
select '2009-12-14 18:0:0' union all
select '2009-12-14 19:0:0' union all
select '2009-12-14 20:0:0' union all
select '2009-12-14 21:0:0' union all
select '2009-12-14 22:0:0' union all
select '2009-12-14 23:0:0' declare @shijian1 varchar(50)
declare @shijian2 varchar(50)set @shijian1='1:20:30'
set @shijian2='5:20:06'select * from @test where shijian between
(substring(convert(varchar(50),shijian,120),1,10) + ' ' + @shijian1)
and (substring(convert(varchar(50),shijian,120),1,10) + ' ' + @shijian2)
select *
from tb
where convert(varchar(8),时间,108) between '00:30:00' and '05:20:06'
如果你想跨日查询,必须在时间信息前加上日期信息...
select * from tb where convert(varchar(8),时间,108) between '00:30:00' and '05:20:06'
and convert(varchar(8),时间,112) between '20091212' and '20091215'