实现批量充优惠券到会员卡中,其中先从ACCESS数据库中取需要充值的会员卡,再使用BDE连接SYBASE数据库,进行操作:
一、DELPHI代码:
procedure TForm1.btn2Click(Sender: TObject);
begin
if (edt1.Text='') or (edt2.Text='') then
begin
  ShowMessage('金额与备注不能为空');
  Exit;
end;

qry1.Open;
qry1.First;
while not qry1.Eof do
begin
  qry2.ParamByName('HYK_NO').AsString:=qry1.Fields[0].AsString;
  qry2.ParamByName('JE').AsInteger:=StrToInt(edt1.Text);
  qry2.ParamByName('ZY').AsString:=edt2.Text;
  qry2.ParamByName('RQ').AsDate:=dtp1.Date;
  qry2.ExecSQL;
  qry1.Next;
end;

ShowMessage('插入完成');
end;

二、SQL代码:
declare @JLBH integer
declare @HYID integer
declare @BH integer
select @JLBH=max(CZJPJ_JLBH)+1 from BFCRM.HYK_CZK_YHQ_CKJL
select @HYID=HYID from BFCRM.HYK_HYXX where HYK_NO=:HYK_NO
select @BH=max(JLBH)+1 from BFCRM.HYK_YHQCLJL where CLLX=1 and MDID IS NULL
update BFCRM.BHZT set REC_NUM=REC_NUM+1 where TBLNAME='HYK_YHQ_CKJL'

insert into BFCRM.HYK_CZK_YHQ_CKJL(CZJPJ_JLBH,HYID,YHQID,JSRQ,YJE,CKJE,ZY,DJR,DJRMC,DJSJ,ZXR,ZXRMC,ZXRQ,CZDD)
 values(@JLBH,@HYID,6,:RQ,0,:JE,:ZY,37,'系统操作员',getdate(),37,'系统操作员',getdate(),'01')

if not exists(select 1 from BFCRM.HYK_YHQZH where HYID=@HYID and YHQID=6 and JSRQ=:RQ)
insert into BFCRM.HYK_YHQZH (HYID,YHQID,JSRQ,JE) values(@HYID,6,:RQ,100)

insert into BFCRM.HYK_YHQCLJL(HYID,CLSJ,CLLX,JLBH,YHQID,JSRQ,ZY,JFJE,DFJE,YE)
 values(@HYID,getdate(),1,@BH,6,:RQ,:ZY,:JE,0,:JE)