比如有以下语句,
procedure TForm1.Button5Click(Sender: TObject);
begin
  with DM2.ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from Stocks');
      
      Open;
    end;
end;如果想给SQL设置一个where,
要求字段InDate必须“>=2008/6/1 and <=2008/6/30”该如何实现??

解决方案 »

  1.   

    忘了说了,字段InDate是日期格式~
      

  2.   

    SQL.Add('select * from Stocks where InDate between :date1 and date2'); 
    Parameters.ParamByName('date1').Value:=StrToDate('2008-06-01');
    Parameters.ParamByName('date2').Value:=StrToDate('2008-06-30');
      

  3.   

    SQL.Add('select * from Stocks where InDate between :date1 and :date2');  
      

  4.   

    SQL.Add('select * from Stocks'); 
    SQL.Add(' where InDate >='+QuotedStr('2008-6-1')); 
    SQL.Add(' and InDate <='+QuotedStr('2008-6-30')); 
      

  5.   

    procedure TForm1.Button5Click(Sender: TObject);
    begin
      with DM2.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from Stocks where InDate>=:date1 and InDate<:date2');
          Parameters.ParamByName('date1').Value:=StrToDate('2008-06-01');
          Parameters.ParamByName('date2').Value:=StrToDate('2008-06-30')+1;       
          Open;
        end;
    end; 
      

  6.   

    非常感谢两位大大,gzmhero大大的方法试过了,可以实现,^_^
    xxmmmx 大大的方法可能哪里还有点问题,提示“标准表达式中数据类型不匹配”,郁闷~
      

  7.   

    procedure TForm1.Button5Click(Sender: TObject); 
    begin 
      with DM2.ADOQuery1 do 
        begin 
          Close; 
          SQL.Clear; 
          SQL.Add('select * from Stocks where InDate between :date1 and :date2'); 
          Parameters.ParamByName('date1').Value:=StrToDate('2008-06-01'); 
          Parameters.ParamByName('date2').Value:=StrToDate('2008-06-30'); 
          Open; 
        end; 
    end; 
      

  8.   

    不好意思,CSDN更新不是很及时,结分的时候没看到你的帖子~
    :(