sql.add('select from view_outgoods');
sql.add('where opDate between '+quotedstr(datetostr(qssj.date))+' and '+quotedstr(datetostr(zzsj.date)));
该sql语句想查在某个日期段的数据,后台数据库是sqlserver,在表中的opdate字段是datetime,如果该字段值只有日期没有时间就可以查处,如果既有日期又有时间时,就不能查出来,这是什么原因呢,该如何该呢???

解决方案 »

  1.   

    可以试一下下面的代码,我在Access中是可以用的,估计要加#号。   
    Sql:=Sql+' and dbill_date >= #'+datetostr(DateFrom)
            +'# and dbill_date <= #'+datetostr(DateTo)+'# '
      

  2.   

    这样写:
    sql.add('select from view_outgoods');
    sql.add('where opDate between '+quotedstr(datetostr(qssj.date)+' 00:00:00')+' and '+quotedstr(datetostr(zzsj.date)+' 23:59:59'));
      

  3.   

    使用formatdatetime函数,我经常用,绝对没问题啊