在前台传入一个日期
如 2010年
后台输出
时间段在2010年的数据 
时间段在2009年的数据 
时间段在2008年的数据 
时间段在2007年的数据 
时间段在2006年的数据 
也就是后面5年的时间段内的数据

解决方案 »

  1.   


    declare @s varchar(100)
    set @='2010'
    select * from tb where datediff(yy,时间列,@s+'-01-01')<=5
      

  2.   


    --如果仅是输出数据,那就不是统计:
    select * from tb where ltrim(year(时间))+'年'=传入的日期年份
      

  3.   

    declare @date int
    set @date=2010select * from tb where datediff(year,[date],rtrim(@date)+'-01-01') between 1 and 5
      

  4.   

    declare @yy int
    set @yy='2010'
    select * from tb where YEAR(时间列) BETWEEN @yy-4 AND @yy
      

  5.   

    @dt为你的变量,这里@dt = 2010
    select * from tb where dt between @dt and @dt - 5
      

  6.   


    select * from tb where @i-年份<=5