time         neirong
2006-3-30     内部会议
2006-3-31     紧急事务处理
2006-2-20     日常工作
1.怎样将上面时间函数中的当年当月的内容提取出来提取出来,上面的时间怎么与系统的时间怎么判断.
2.如果本月是四月,提取上个月的内容怎么提取,既上面三月的内容,请大家帮忙.

解决方案 »

  1.   

    2.
    select * from tablename where datediff(month,[time],getdate())=1
      

  2.   

    1.怎样将上面时间函数中的当年当月的内容提取出来提取出来,上面的时间怎么与系统的时间怎么判断.前半句不是很明白,不知道是不是这个意思
    select month(getdate())
    select day(getdate())与系统时间比较可以用datediff
      

  3.   

    select * from tablename where DATEPART (day,time)<4
      

  4.   

    select * from tablename where DATEPART (day,time)<4 and DATEPART (year,time)<2006
      

  5.   

    --当年当月
    select * 
    from tablename  
    where year(time)=year(getdate()) and month(time)=month(getdate())
      

  6.   

    select * from tablename where datediff(month,[time],getdate())=0 and datediff(year,[time],getdate())=0
      

  7.   

    上个月的。 
    select * 
    from tablename  
    where year(time)=year(getdate()) and month(time)=month(dateadd(mm,-1,getdate()))