select * from 数据表 where datepart(yyyy,pubdate)='2002'

解决方案 »

  1.   

    select * from 表 where datepart(yy,attdate)=2002
      

  2.   

    或者select * from 数据表 where convert(varchar(4),pubdate)='2002'
      

  3.   

    select * from 表 where year(pubdate)= 2002
      

  4.   

    改:select * from 数据表 where convert(varchar(4),pubdate,120)='2002'
      

  5.   

    select * from 表 where year(attdate)=2002
      

  6.   

    select * from 表 where year(attdate) = 2002select * from 表 where convert(char(4),attdate,120) = '2002'select * from 表 where datepard(year,attdate) = 2002select * from 表 where datediff(year,'2002-01-01',attdate) = 0
      

  7.   

    查2001年1月份的:
    select * from 表 where convert(char(7),attdate,120) = '2002-01'
      

  8.   

    select * from 表 where year(attdate) = 2002 and month(attdate)=11
    --or:
    select * from 表 where convert(char(7),attdate,120) = '2002-11'
      

  9.   

    如果要查哪一年哪一月的呢?
    ----------------------------------------------------------------
    比如查询2002年6月select * from 表 where year(attdate) = 2002 and month(attdate) = 6select * from 表 where convert(char(7),attdate,120) = '2002-06'select * from 表 where datepard(year,attdate) = 2002 and datepard(month,attdate) = 6select * from 表 where datediff(month,'2002-06-01',attdate) = 0
      

  10.   

    查2001年1月份的:
    select * from 表 where convert(char(7),attdate,120) = '2002-01'
    -------------------
    后面那个120表示什么?