1、qry1:
select X.HYID '会员ID',X.HYK_NO '会员卡号',X.HY_NAME '会员名称',X.JKRQ '建卡日期',min(L.JZRQ) '消费日期',sum(L.JE) '消费金额'
from BFCRM.HYK_HYXX X,BFCRM.HYXFJL L,BFBHDD.SKTXSJLM M
where X.HYID=L.HYID
and L.SKTNO=M.SKTNO
and L.JLBH=M.JLBH
and M.SKFS in (1,2)
and X.JKRQ<='2011-11-1 08:00:00'
group by X.HYID,X.HYK_NO,X.HY_NAME,X.JKRQ
having min(L.JZRQ)<=:RQ2 and min(L.JZRQ)>=:RQ1 and sum(L.JE)>=:JE
order by '消费金额'
2、qry2:
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,'11月首次消费满200赠积分',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
3、delphi代码:
procedure TForm1.btn1Click(Sender: TObject);
begin
if edt1.Text='' then
begin
ShowMessage('输入消费金额');
Exit;
end;
qry1.ParamByName('RQ1').AsDate:=dtp1.Date;
qry1.ParamByName('RQ2').AsDate:=dtp2.Date;
qry1.ParamByName('JE').AsInteger:=StrToInt(edt1.Text);
qry1.Open;
dbgrd1.Columns[0].Width:=50;
dbgrd1.Columns[1].Width:=60;
dbgrd1.Columns[2].Width:=60;
dbgrd1.Columns[3].Width:=70;
dbgrd1.Columns[4].Width:=70;
dbgrd1.Columns[5].Width:=60;
btn2.Enabled:=True;
end;
procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then btn1.SetFocus;
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
if edt2.Text='' then
begin
ShowMessage('请输入需增加的积分');
edt2.SetFocus;
Exit;
end;
qry1.ParamByName('RQ1').AsDate:=dtp1.Date;
qry1.ParamByName('RQ2').AsDate:=dtp2.Date;
qry1.ParamByName('JE').AsInteger:=StrToInt(edt1.Text);
qry1.Open;
qry1.First;
while not qry1.eof do
begin
qry2.ParamByName('JF').AsInteger:=StrToInt(edt2.Text);
qry2.ParamByName('HYID').AsInteger:=qry1.Fields[0].AsInteger;
qry2.ExecSQL;
qry1.Next;
end;
btn2.Enabled:=False;
end;