一、qry1:
select H.HYID,sum(C.SKJE) JE,sum(H.JF) JF
from BFCRM.HYXFJL H,BFBHDD.SKTXSJLM C,BFBHDD.SKTXSJL L
where L.SKTNO=C.SKTNO
and L.JLBH=C.JLBH
and H.SKTNO=L.SKTNO
and H.JLBH=L.JLBH
and H.HYID is not null
and C.SKFS in (1,2)
and L.JZRQ>=:RQ1
and L.JZRQ<=:RQ2
group by HYID
having sum(C.SKJE)>:JE1 and sum(C.SKJE)<=:JE2
二、qry5:
declare @JLBH integer
select @JLBH=max(JLBH)+1 from BFCRM.HYK_JFTZJL
update BFCRM.BHZT set REC_NUM=REC_NUM+1 where TBLNAME='HYK_JFTZJL'
insert into BFCRM.HYK_JFTZJL(JLBH,MDID,SKTNO,XSJYBH,HYID,XSRQ,TZJF,ZY,DJR,DJRMC,DJSJ,ZXR,ZXRMC,ZXRQ,TZJE,ZY1,JF_JE)
values(@JLBH,0,'999',-99999,:HYID,'',:JF,'积分增加',37,'系统操作员',getdate(),37,'系统操作员',getdate(),0,'年终会员积分翻倍送',0)
update BFCRM.HYK_MDJF set WCLJF=WCLJF+:JF where MDID=0 and HYID=:JF
update BFCRM.HYK_JFZH set WCLJF=WCLJF+:JF where HYID=:HYID
三、执行语句:
procedure TForm1.btn2Click(Sender: TObject);
var
//jf:Integer;
bs:Integer;
begin
ds1.DataSet:=qry1;
qry1.ParamByName('RQ1').AsDate:=dtp1.Date;
qry1.ParamByName('RQ2').AsDate:=dtp2.Date;
qry1.ParamByName('JE1').AsInteger:=StrToInt(edt1.Text);
qry1.ParamByName('JE2').AsInteger:=StrToInt(edt2.Text);
qry1.Open;
//jf:=qry1.Fields[2].AsInteger;
bs:=StrToInt(edt3.Text);
qry1.First;
while not qry1.Eof do
begin
qry5.ParamByName('HYID').AsInteger:=qry1.Fields[0].AsInteger;
qry5.ParamByName('JF').AsInteger:=qry1.Fields[2].AsInteger*bs;
qry5.ExecSQL;
qry1.Next;
end;
ShowMessage('积分已录入');
qry1.Close;
end;