declare @t datetime set @t='2006-12-20'select * from Tname where datediff(dd,ColDate,@t)>=25 select * from Tname where datediff(dd,@t,ColDate)>=25
select * from tab where col1 between getdate() and DATEADD(day,25,getdate()) select * from tab where col1 > DATEADD(day,25,getdate())
select * from tbname where abs(datediff(dd,ColDate,@t))>=25
if object_id('t') is not null drop table t go create table t(id varchar(10),ntime datetime) insert t select '1','2007-2-3' union all select '2','2007-1-30' union all select '5','2007-1-4' union all select '7','2007-2-8' union all select '8','2007-2-28' union all select '9','2007-3-19' union all select '10','2007-4-27' union all select '22','2007-1-5' go select * from t goselect id,ntime from t where ntime < getdate()-25 select id,ntime from t where ntime > getdate()+25
以五天为例 create table mydemo(date datetime,valueid int identity(1,1)) insert into mydemo select '2006-12-12' union all select '2006-12-13' union all select '2006-12-17' union all select '2006-12-23' union all select '2006-12-29' union all select '2006-12-30' union all select '2007-1-1' union all select '2007-1-2' union all select '2007-1-3' union all select '2007-1-4' union all select '2007-1-5' union all select '2007-1-8' union all select '2007-1-9' union all select '2007-1-13' union all select '2007-1-12'select * from(select top 5 * from mydemo where date <='2007-1-3' order by date desc)a union select * from(select top 5 * from mydemo where date >='2007-1-3' order by date)b
当天查询25天以后的数据???会有吗???当天查询25天以前的数据 select * from tabname where datediff(dd,ColDate,getdate())>=25
select * from Tname where createtime>getdate()-25 and createtime<getdate()+25
set @t='2006-12-20'select * from Tname where datediff(dd,ColDate,@t)>=25
select * from Tname where datediff(dd,@t,ColDate)>=25
select * from tab where col1 > DATEADD(day,25,getdate())
drop table t
go
create table t(id varchar(10),ntime datetime)
insert t select '1','2007-2-3'
union all select '2','2007-1-30'
union all select '5','2007-1-4'
union all select '7','2007-2-8'
union all select '8','2007-2-28'
union all select '9','2007-3-19'
union all select '10','2007-4-27'
union all select '22','2007-1-5'
go
select * from t
goselect id,ntime from t where ntime < getdate()-25
select id,ntime from t where ntime > getdate()+25
create table mydemo(date datetime,valueid int identity(1,1))
insert into mydemo select '2006-12-12'
union all select '2006-12-13'
union all select '2006-12-17'
union all select '2006-12-23'
union all select '2006-12-29'
union all select '2006-12-30'
union all select '2007-1-1'
union all select '2007-1-2'
union all select '2007-1-3'
union all select '2007-1-4'
union all select '2007-1-5'
union all select '2007-1-8'
union all select '2007-1-9'
union all select '2007-1-13'
union all select '2007-1-12'select * from(select top 5 * from mydemo where date <='2007-1-3' order by date desc)a
union
select * from(select top 5 * from mydemo where date >='2007-1-3' order by date)b
select * from tabname where datediff(dd,ColDate,getdate())>=25