在数据库中存在1992-08-27 00:00:00.000这样的时间形式,我想要查找某一月,某一年的
这样写有什么不对,
select * from employee where hire_date like '1992_'select * from employee where hire_date like '[-08-]'select * from employee where hire_date like '_08_' 为什么查不到,谢谢

解决方案 »

  1.   

    select * from employee where datepart(yy,hire_date)=1992select * from employee where datepart(mm,hire_date)=8
      

  2.   

    或者
    datename(yy,hire_date)='1992'datename(yy,hire_date)='08'
      

  3.   

    SLECT * FROM employee WHERE YEAR(hire_date)=1992
      

  4.   

    select * from employee where hire_date like '1992-*' select * from employee where hire_date like '*-08-*' select * from employee where hire_date like '*-08-*'
      

  5.   

    _匹配单个字符。
    -放在[]里表示范围另外,你的是datetime,不建议使用like查询。查1992年所有
    select * from employee where dte >='1992-1-1' and dte <'1993-1-1'
    查1992年3月所有
    select * from employee where dte >='1992-3-1' and dte <'1992-4-1'
      

  6.   

    year(字段名)
    month(字段名)
    day(字段名)