select * 
from a
where datediff(dd, date1, date2)>2

解决方案 »

  1.   

    --测试数据
    create table a(id varchar(10), date1 datetime, date2 datetime)
    insert a  select '01', '2001-01-01', '2001-01-06'
    union all select '02', '2004-05-09', '2009-05-15'
    union all select '03', '2005-01-06', '2005-01-07'
    union all select '03', '2005-01-06', '2005-01-07'
    --查询
    select count(1)
    from a
    where datediff(dd, date1, date2)>2
    --清除
    drop table a
      

  2.   

    select count(1) from A
    where datediff(day,Date1,Date2)>2
      

  3.   

    select * from A where datediff(day,Date1,Date2)>2
      

  4.   

    select count(*) from A where datediff(day,Date1,Date2)>2
      

  5.   

    declare @a int ,@b int,@c int
    select @a=date1 from 表名
    select @b=date2 from 表名
    select @c=@b-@a
    if select * from 表名 where @c>2
    print @c
      

  6.   

    select count(1) from A where datediff(day,Date1,Date2)>2
    函数DATEDIFF 返回跨两个指定日期的日期和时间边界数。 
    语法
    DATEDIFF ( datepart , startdate , enddate ) 
    改变参数datepart 可以改变返回的值,比如可以返回两个日期相隔的日期/年/时/分/秒
    具体参数说明可以看SQL的帮助