在SQL语句中如何查找本日所在的当月和当年的以前的记录,数据库是access,delphi7开发.

解决方案 »

  1.   

    小于等于当日的当月记录和
    小于等于当日的当年记录
    当月的我知道,如下:
    SQl.Add('select sum(cashincome) as cashincome from cashturnover where cashitem=:fcashitem and year(cashdate)=:fcashyear and month(cashdate)=:fcashmonth and day(cashdate)<=:fcashday');
    Parameters.ParamByName('fcashitem').Value:='其他收入';
    Parameters.ParamByName('fcashyear').Value:=strtoint(FormatDateTime('yyyy',Datetimepicker1.Date));
    Parameters.ParamByName('fcashmonth').Value:=strtoint(FormatDateTime('mm',Datetimepicker1.Date));
    Parameters.ParamByName('fcashday').Value:=strtoint(FormatDateTime('dd',Datetimepicker1.Date));
    当年的如何写??
      

  2.   

    我的習慣是記錄里面加個流水號字段,流水號等于formatdatetime('yyyymmddhhnnss',now)
    到了查固定時間的記錄時候用流水號標識。相當準確,呵呵
      

  3.   

    cashdate肯定是日期型吧?
    SQl.Add('select sum(cashincome) as cashincome from cashturnover where cashitem=:fcashitem and year(cashdate)=:fcashyear and cashdate<=:fcashday'); 
    Parameters.ParamByName('fcashitem').Value:='其他收入'; 
    Parameters.ParamByName('fcashyear').Value:=strtoint(FormatDateTime('yyyy',Datetimepicker1.Date)); 
    Parameters.ParamByName('fcashday').Value:=FormatDateTime('yyyy-mm-dd',Datetimepicker1.Date));