以下代码在D5+Access2000+Windows2000下运行通过
var
iM, iY, iD, iM1, iY1 : Word;
sD1, sD2 : string;
begin
DecodeDate(Date, iY, iM, iD);
sD1 := IntToStr(iY) + '-' + IntToStr(iM) + '-' + '01'; //本月第一天
if iM = 12 then
begin
iM1 := 1;
iY1 := iY + 1;
end
else
Begin
iM1 := iM + 1;
iY1 := iY;
End;
sD2 := IntToStr(iY1) + '-' + IntToStr(iM1) + '-' + '01'; //下个月第一天
with Query do
Begin
Close;
Sql.Clear;
Sql.Add('SELECT * FROM RWD WHERE RQ>=:v_rq1 AND RQ<:v_rq2');//大于等于本月第一天,小于下月第一天,这样做的好处就是可以不管本月总共是几天
Parameters.ParamByName('v_rq1').Value := StrToDate(sD1);
Parameters.ParamByName('v_rq2').Value :=StrToDate(sD2);
Open;
End;