select datediff(hh,'2008-11-27 18:00:00',getdate())----------- 
3

解决方案 »

  1.   

    就是字符串查询,SQL SERVER会隐式的转换了VARCHAR(40)去查询,你可以看执行计划。
    你要知道为什么查不出来,你看看你执行下面的的数据是什么就知道了:
    selelct convert(varchar(40),dtTime) from xx
      

  2.   

    if object_id('tempdb..#')is not null drop table #
    go
    create table #(dtTime datetime)
    insert # select '2009-08-12 17:21:00.000'
    insert # select '2008-08-11 17:21:00.000'
    insert # select '2008-09-11 16:21:00.000'
    insert # select '2007-06-11 08:21:00.000'
    select * from # where datepart(mm,dtTime)='08' and datepart(dd,dtTime)='11'
    and datepart(hh,dtTime)='17'
    /*dtTime                                                 
    ------------------------------------------------------ 
    2008-08-11 17:21:00.000
    */
      

  3.   

    %
    匹配包含零个或多个字符的任意字符串-
    匹配涉及模式匹配的字符串比较操作(如 LIKE 和 PATINDEX)中的任何单个字符