能否对convert,between 进行优化?
比如:
select *
from table
where (convert(char(10),a.dTransDT,120) between 'beginTime ' and 'endTime ') and ...因为这个函数很耗时

解决方案 »

  1.   

    --不转化也可以达到效果的
    select *
    from table
    where (a.dTransDT between @beginTime and @endTime) and ...
      

  2.   

    用时间做查询最好不要用函数,特别是在时间上建了索引,直接用日期型进行查询
    Coldate between ... and ..
      

  3.   

    @beginTime 
    加@有什么含义?
    select *
    from table a
    where (convert(char(10),a.dTransDT,120) between '2006-06-01 ' and  '2006-07-02 ')  and ...select *
    from table a
    where (a.dTransDT between @'2006-06-01 'and @'2006-07-02 ') and ...这样?
      

  4.   

    @beginTime是变量,代表'2006-10-10'
      

  5.   

    因为在数据库中,dTransDT是 year:month:day  hh:mm:ss.*** 格式
    比如 '2006-10-10 12:26:25.256 '
    不知道,convert(char(10),a.dTransDT,120) between '2006-06-01 ' and  '2006-07-02 ')得到的结果是否和(a.dTransDT between '2006-06-01 'and '2006-07-02 ')一样?
      

  6.   

    不用转化的,sql会自动认识的
    convert(char(10),a.dTransDT,120) between '2006-06-01 ' and  '2006-07-02 ')得到的结果是和(a.dTransDT between '2006-06-01 'and '2006-07-02 ')一样
      

  7.   

    因为是为了优化
    所以要转化convert函数
      

  8.   

    我在把convert转化后,得到的结果中间,一部分是正确的,一部分确实错误的
    这是为什么?
      

  9.   

    因为根本就不需要转换。select *
    from table a
    where a.dTransDT between '2006-06-01' and '2006-07-02'“因为是为了优化,所以要转化convert函数”
    转了反而是错的。
      

  10.   

    因为convert比较耗时
    要优化这个时间表示方式
    请大家多多指教
      

  11.   

    不需要convert就可以比较
    这是Datetime的特殊性
      

  12.   

    select *
    from table a
    where a.dTransDT between '2006-06-01' and '2006-07-02'
      

  13.   

    不用convert行吗?
    比如a.dTransDT时间为:'2006-07-02 08:00:00'select *
    from table a
    where a.dTransDT between '2006-06-01' and '2006-07-02'
    应该查不到