SQL拼接

var  
  MSQLField:string;//SQL语句  
  MSQLTerm:string;//拼接语句  
  MErrorInfoStr:string;//错误语句  
  i :Integer;     
begin  
  inherited;  
  MSQLField := '';  
  MSQLTerm := '';  
  MErrorInfoStr := '短信发送设置查询出错,请重新查询!!!';  
  
  //拼接SQL语句  
  MSQLField := MSQLField + 'select ssc.DeliStano, ssc.SDClno, ssc.CreateDateTime, ssc.CreateOperator,' + #13   
                        + 'ssc.Hour,s.Station as DeliStation, c.Chname as SDShipp from msSMSSendCondition ssc' + #13  
                        + 'left outer join bStat s on ssc.DeliStano = s.Stano' + #13      
                        + 'left outer join bCust c on ssc.SDClno = c.Clno ' + #13;  
  
  
  // 如果客户不为空  
  if RzButtonEditSearchSearchSDShipp.text <> ''  then  
  begin  
    if MSQLTerm = '' then  
    begin  
       MSQLTerm := MSQLTerm + 'ssc.SDClno   = ' + quotedstr(RzButtonEditSearchSearchSDShipp.RzEdit.Text) + #13;  
    end else begin  
       MSQLTerm := MSQLTerm + ' and  ssc.SDClno   = ' + quotedstr(RzButtonEditSearchSearchSDShipp.RzEdit.Text) + #13;  
    end;  
  end;  
  
  if RzButtonEditSearchStation.text <> ''  then  
  begin  
    if MSQLTerm = '' then  
    begin  
       MSQLTerm := MSQLTerm + 'ssc.DeliStano  = ' + quotedstr(RzButtonEditSearchStation.RzEdit.Text) + #13;  
    end else begin  
       MSQLTerm := MSQLTerm + ' and ssc.DeliStano  = ' + quotedstr(RzButtonEditSearchStation.RzEdit.Text) + #13;  
    end;   
  end;  
  
  if MSQLTerm <> '' then  
  begin  
     MSQLTerm := 'where ' + MSQLTerm;  
  end;  
[delphi] view plaincopy
  SynchReadData(Handle, MSQLField + MSQLTerm, ClientDataSet, MErrorInfoStr);  

posted @ 2014-12-20 10:34  生命不息大道不止  阅读(191)  评论(0)    收藏  举报