我选择条件只有月和日起始值和截止日,现在要查询出每年在在这个时间的内的记录例如:
1 2007-02-01
2 2005-09-15
3 2001-01-01结果:
1 2007-02-01
这样我要的结果是如果查询1月5号到2月5号的就只有记录1.
1 2007-02-01
2 2005-09-15
3 2001-01-01结果:
1 2007-02-01
这样我要的结果是如果查询1月5号到2月5号的就只有记录1.
insert into tb values(1, '2007-02-01')
insert into tb values(2, '2005-09-15')
insert into tb values(3, '2001-01-01')
goselect * from tb where right(convert(varchar(10),rq,120),5) between '01-05' and '02-05'drop table tb/*
id rq
----------- ------------------------------------------------------
1 2007-02-01 00:00:00.000(所影响的行数为 1 行)
*/
insert into @t
select 1,'2007-02-01'
union select 2,'2005-09-15'
union select 3,'2001-01-01'
select * from @t where substring(date,6,2)+substring(date,9,2) between '0105' and '0205'
insert into @t select 1,'2007-02-01'
insert into @t select 2,'2005-09-15'
insert into @t select 3,'2001-01-01'
select * from @t
where dt between ltrim(year(dt))+'-01-05' and ltrim(year(dt))+'-02-05'
select * from tb where ltrim(str(datepart(month,rq)))+'-'+ltrim(str(datepart(day,rq))) between '1-5'and '2-5'
不知道这样可行吗?:)