数据库
ID createTime arriveTime
1 2008-07-30 14:36:49 2008-09-10 14:36:49
2 2008-05-30 14:36:49 2009-07-30 14:36:49
3 2008-07-30 14:36:49 2008-08-05 14:36:49我要找出arriveTime离现在不满一个月的ID,这个SQL语句怎么写,也就是快要到期的ID列出来
ID createTime arriveTime
1 2008-07-30 14:36:49 2008-09-10 14:36:49
2 2008-05-30 14:36:49 2009-07-30 14:36:49
3 2008-07-30 14:36:49 2008-08-05 14:36:49我要找出arriveTime离现在不满一个月的ID,这个SQL语句怎么写,也就是快要到期的ID列出来
Insert @T
select 1,'2008-07-30 14:36:49','2008-09-10 14:36:49' union all
select 2,'2008-05-30 14:36:49','2009-07-30 14:36:49' union all
select 3,'2008-07-30 14:36:49','2008-08-05 14:36:49'
Select
*
from
@T
where
dateadd(m,1,getdate())>=[arriveTime]
if object_id('数据库') is not null
drop table 数据库
go create table 数据库
( ID int ,
createTime datetime,
arriveTime datetime
)
insert into 数据库 select 1,'2008-07-30 14:36:49','2008-09-10 14:36:49'
union all select 2,'2008-05-30 14:36:49','2009-07-30 14:36:49'
union all select 3,'2008-07-30 14:36:49','2008-08-05 14:36:49'
go
select ID from 数据库 where month(arriveTime)<=month(getdate())
select ID from tb
where arriveTime < getdate() and dataadd(m,1,arriveTime) > getdate()