有一表message:
编号 内容 发送日期 有效天数
1 ... 2007-1-1 3
2 ... 2007-7-7 7
3 ... 2007-2-2 1
...
要求:统计当日有效(在有效期内)的通知条数
编号 内容 发送日期 有效天数
1 ... 2007-1-1 3
2 ... 2007-7-7 7
3 ... 2007-2-2 1
...
要求:统计当日有效(在有效期内)的通知条数
1 ... 2007-1-1 3
2 ... 2007-7-7 7
3 ... 2007-2-2 1
...
要求:统计当日有效(在有效期内)的通知条数
----------------------
select count(*)as 條數from t
where dateadd(dd,有效天数,发送日期)>=convert(varchar(10),getdate(),120)
where dateadd(dd,有效天数,发送日期)>=convert(varchar(10),getdate(),120)
----------
不用做類型轉換
select count(*)as 條數from t
where dateadd(dd,有效天数,发送日期)>=getdate()
(id int, 發送日期 varchar(10), 有效天數 int)
insert into t
select 1, '2007-1-1', 3 union all
select 2, '2007-7-7', 7 union all
select 3, '2007-2-2', 1
select count(*)as 條數 from t
where dateadd(dd,有效天數,發送日期)>=convert(varchar(10),getdate(),120)
條數
-----------
1(1 row(s) affected)