Delphi中操作sql代码

一个例子:

 with QryTemp do begin
     if Active then close;
     sql.Clear;
     //    select dsjbh,qh,uphone,zjtype,uzjsj,checkflag from user_card
     sql.Text:='update user_card set checkflag=1 where'
      +' dsjbh=:dsjbh and uphone=:phone and qh=:qh';
     Parameters.ParamByName('dsjbh').Value:=dsjbh;
     Parameters.ParamByName('phone').Value:=uphone;
     Parameters.ParamByName('qh').Value:=qh;
     ExecSQL;

另一个例子:

  with qrypx do begin
      close;//    select
      sql.Clear;
      sql.text:='select top 30 dsjbh,qh,zjtype,uphone,uzjsj,checkflag from user_card '
      +'where uzjsj>=:uzjsj and checkflag=0 order by uzjsj,uphone';
      Parameters.ParamByName('uzjsj').Value:=lastzjtime;
      open;
      if recordcount>0 then begin
        while not eof do begin
          Application.ProcessMessages();
          sleep(1);
          if(bExitFlag) then break;
          strqh:=trim(Fieldbyname('qh').AsString);
          strphone:=trim(Fieldbyname('uphone').AsString);
          strdsjbh:=trim(Fieldbyname('dsjbh').AsString);
          strZjtype:=trim(Fieldbyname('zjtype').AsString);//添加装机类型
          zjtime:=Fieldbyname('uzjsj').AsDateTime;

第三个例子:

          try
   with QryTemp do begin
     if Active then close;
     sql.Clear;
     sql.Text:='select mkbh from haomaduan '
     +'where dsjbh='''+strdsjbh+''' and qh='''+ strqh
     + ''' and ((cast(starthao as bigint)<='+strphone+
      ')and (cast(endhao as bigint)>='+strphone+'))';
     open;
     if recordcount>0 then  result:=trim(fieldbyname('mkbh').AsString)
     else result:='-1'
   end;
 except
   result:='-1';
 end;

原文地址:https://www.cnblogs.com/feng801/p/1274221.html