select time from Table1 where time datediff(month,20090908,20090909)=1
请给个能正确运行的代码这样出错啊
消息 4145,级别 15,状态 1,第 1 行
在应使用条件的上下文(在 'datediff' 附近)中指定了非布尔类型的表达式。

解决方案 »

  1.   

    select [time] 
    from Table1 
    where convert(varchar(7),[time],120) between '2009-08' and '2009-09' 
      

  2.   

    select [time] 
    from Table1 
    where datediff(month,[time],'20090909') between 0 and 1 
      

  3.   

    我再问的简单点。。有个time列,里面有条数据时 '2009-9-29 18:47:04' 我怎么就查不到呢,兄弟们帮我看看我的sql语句:select time from article where time='2009-9-29 18:47:04'
      

  4.   

    月份是两位的,用09,还有datetime型一般含有毫秒数据,所以不建议这样直接去匹配
      

  5.   

    select time from article where convert(varchar(19),[time],120)='2009-09-29 18:47:04'
      

  6.   

    哦,谢谢你。原来查询时间,SQL与语句里一定要改成varchar类型啊
    有没有convert转换成时间类型的呢?
      

  7.   


    如果是时间格式的数据,用cast()就可以了select cast('2009-09-29 18:47:04' as datetime)/**
                                                           
    ------------------------------------------------------ 
    2009-09-29 18:47:04.000(所影响的行数为 1 行)
    **/