有一表message:
编号 内容  发送日期 有效天数
1    ...   2007-1-1  3
2    ...   2007-7-7  7
3    ...   2007-2-2  1
...
要求:统计当日有效(在有效期内)的通知条数

解决方案 »

  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)
      

  2.   

    Select * From message Where DateDiff(dd, 发送日期, GetDate()) Between 0 And 有效天数
      

  3.   

    少了統計Select Count(*) As 通知条数 From message Where DateDiff(dd, 发送日期, GetDate()) Between 0 And 有效天数
      

  4.   

    select count(*)as 條數from t
    where dateadd(dd,有效天数,发送日期)>=convert(varchar(10),getdate(),120)
    ----------
    不用做類型轉換
    select count(*)as 條數from t
    where dateadd(dd,有效天数,发送日期)>=getdate()
      

  5.   

    create table t
    (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)