使用当前日期?在条件语句中可以使用getdate()函数。

解决方案 »

  1.   

    刚回的一个帖子,不知道对楼主有没有参考作用:
    ------------------------------------------------------------------
    create table T_AA(col varchar(20))
    insert into T_AA select '20050901001'
    insert into T_AA select '20050906001'
    insert into T_AA select '20050907001'
    insert into T_AA select '20050908001'
    insert into T_AA select '20050909001'
    insert into T_AA select '20050912001'
    insert into T_AA select '20050915001'
    insert into T_AA select '20050901001'
    insert into T_AA select '20050922001'
    insert into T_AA select '20050922002'
    insert into T_AA select '20050922003'
    insert into T_AA select '20050923001'
    insert into T_AA select '20050922002'
    insert into T_AA select '20050922003'
    go
    create view v1 as
    select
        *
    from
        T_AA
    where
        datediff(dd,cast(left(col,8) as datetime),getdate())<15
    go
    select * from v1
    /*
    col
    -----------
    20050908001
    20050909001
    20050912001
    20050915001
    20050922001
    20050922002
    20050922003
    20050923001
    20050922002
    20050922003
    */
      

  2.   

    getdate()
    CREATE VIEW dbo.VIEW1
    AS
    SELECT GETDATE() AS date
    是这个意思吗???
      

  3.   

    create view v
    as
    select (case when getdate()<='2005-09-22' then 1 else 2 end) 'num'go--查询 
    select * from v--结果
    /*
    num         
    ----------- 
    2(所影响的行数为 1 行)
    */