我的数据表里有一列 “修改时间”是:2009-07-12 11:25:12
2009-06-10 11:25:12
2008-04-15  12:15:44……现在我想 取出所有年是 2009 年的数据,应该怎么写?

解决方案 »

  1.   

    select *
    from tb
    where year(datefield)=2009
      

  2.   

    select * from tb where year(修改时间)=2009
      

  3.   

    select *
    from tb
    where year(修改时间)=2009
      

  4.   

    本帖最后由 libin_ftsafe 于 2009-07-08 16:11:16 编辑
      

  5.   


    1.select * from tbl_charge where charindex('2009',recordDate)>0
    2.select * from tb where year(修改时间)=2009
      

  6.   

    select * from tb where year('日期字段')=2009
      

  7.   

    select *
    from tb
    where left(修改时间, 4)=2009
      

  8.   

    建议楼主用这个   
    select 
    * from 
    tb where convert(varchar,修改时间,112) like '2009%'  或者是这个:   
    select 
    * from 
    tb where left(convert(varchar,修改时间,112),4)='2009'
      

  9.   

    本帖最后由 hery2002 于 2009-07-08 19:48:24 编辑
      

  10.   

    select * from 表 where DATENAME(yy,修改时间)='2009'
      

  11.   

    select * from table where year([time])=2009
    select * from table where [time]>=2009-1-1 and [time]<2010-1-1
      

  12.   


    你用的不是mssql么?如果是就记得 这个convert()函数的用法吧,我的例子里已经写清楚了
    主要这样可以准确的吧日期数据类型转换成为字符型,这样更方便
    而其他的 写法比如 修改时间>='2009-01-01' 可是可以
    但是,有的时候会出现一点问题,比如说用between 的时候,可能会没有包含2009-01-01这一天
    反正我经常都是用convert()转换成字符形的。
      

  13.   

    select *
    from tb
    where year(datefield)=2009