哪位高手能将这段SQL改为存储过程,感谢!!!

dqj 2004-10-10 12:49:40

//汇总库存 如果要汇总2004年10期的数据, mytotalware(2004,10)

procedure TFormTotalWare.myTotalWare(year,month:word);
var
batchno,Seekdate,tempname,houseno,wareno,period:string;
id:integer;
time0,time1:TTime;
begin
if Month>1 then period:=inttostr(Year)+strright(' '+inttostr(Month-1),2)
else period:=inttostr(Year-1)+'12';
Seekdate:=inttostr(Year)+strright(' '+inttostr(Month),2);
tempname:='#'+getrandom;
while tempname=getrandom do tempname:='#'+getrandom;

time0:=time;
tempname:='#0'+getrandom;
LabelMess.Caption:='正在处理当前库存,请稍候......';
LabelMess.update;
query1.close;
query1.sql.text:='delete from waresum where period="'+Seekdate+'"';
query1.execsql;

LabelMess.Caption:='正在汇总当前库存,请稍候......';
LabelMess.update;
//期初
Query1.close;
query1.sql.clear;
query1.sql.add('select wareno,houseno,curr,amount,0 as tag');
query1.sql.add('into '+tempname);
query1.sql.add('from waresum where period="'+period+'" and (amount<>0 or curr<>0)');
query1.sql.add('union all ');
//采购
query1.sql.add('select b.wareno,a.houseno,sum(b.curr) as curr,sum(b.amount) as amount,0 as tag');
query1.sql.add('from wareinh a,wareinm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno');
query1.sql.add('group by b.wareno,a.houseno');
query1.sql.add('union all ');
//调价
query1.sql.add('select b.wareno,a.houseno,sum(b.curr) as curr,0 as amount,1 as tag');
query1.sql.add('from adjusth a,adjustm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno');
query1.sql.add('group by b.wareno,a.houseno');
query1.sql.add('union all ');
//采购退货
query1.sql.add('select b.wareno,a.houseno,-sum(b.curr) as curr,-sum(b.amount) as amount,1 as tag');
query1.sql.add('from refundinh a,refundinm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno');
query1.sql.add('group by b.wareno,a.houseno');
query1.sql.add('union all ');
//调入
if pCbtjfs=1 then query1.sql.add('select b.wareno,a.newhouseno as houseno,sum(b.curr) as curr,sum(b.amount) as amount,1 as tag')
else query1.sql.add('select b.wareno,a.newhouseno as houseno,sum(b.fixedcurr) as curr,sum(b.amount) as amount,1 as tag');
query1.sql.add('from warealloth a,wareallotm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno');
query1.sql.add('group by b.wareno,a.newhouseno');
query1.sql.add('union all ');
//其他入库
query1.sql.add('select b.wareno,a.houseno,sum(b.curr) as curr,sum(b.amount) as amount,1 as tag');
query1.sql.add('from otherinh a,otherinm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno');
query1.sql.add('group by b.wareno,a.houseno');
{query1.sql.add('union all ');
//组装入库
query1.sql.add('select a.wareno,a.houseno,sum(a.curr) as curr,sum(a.amount) as amount,1 as tag');
query1.sql.add('from waremakeh a where a.period="'+seekdate+'"');
query1.sql.add('group by a.wareno,a.houseno');
query1.sql.add('union all ');
//拆装入库
query1.sql.add('select b.wareno,a.houseno,sum(b.curr) as curr,sum(b.amount) as amount,1 as tag');
query1.sql.add('from waretearh a,waretearm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno');
query1.sql.add('group by b.wareno,a.houseno');}
query1.sql.add('union all ');
//发货
query1.sql.add('select b.wareno,a.houseno,-sum(b.fixedcurr) as curr,-sum(b.amount) as amount,1 as tag');
query1.sql.add('from wareouth a,wareoutm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno');
query1.sql.add('group by b.wareno,a.houseno');
query1.sql.add('union all ');
//销售退货
query1.sql.add('select b.wareno,a.houseno,sum(b.fixedcurr) as curr,sum(b.amount) as amount,1 as tag');
query1.sql.add('from refundouth a,refundoutm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno');
query1.sql.add('group by b.wareno,a.houseno');
query1.sql.add('union all ');
//调出
query1.sql.add('select b.wareno,a.oldhouseno as houseno,-sum(b.fixedcurr) as curr,-sum(b.amount) as amount,1 as tag');
query1.sql.add('from warealloth a,wareallotm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno');
query1.sql.add('group by b.wareno,a.oldhouseno');
query1.sql.add('union all ');
//其他出库
query1.sql.add('select b.wareno,a.houseno,-sum(b.fixedcurr) as curr,-sum(b.amount) as amount,1 as tag');
query1.sql.add('from otherouth a,otheroutm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno');
query1.sql.add('group by b.wareno,a.houseno');
query1.sql.add('union all ');
//盘盈
query1.sql.add('select b.wareno,a.houseno,sum(b.curr) as curr,sum(b.amount) as amount,1 as tag');
query1.sql.add('from warecheckh a,warecheckm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno and a.tag=1 and b.amount>0');
query1.sql.add('group by b.wareno,a.houseno');
query1.sql.add('union all ');
//盘亏
query1.sql.add('select b.wareno,a.houseno,sum(b.fixedcurr) as curr,sum(b.amount) as amount,1 as tag');
query1.sql.add('from warecheckh a,warecheckm b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno and a.tag=1 and b.amount<0');
query1.sql.add('group by b.wareno,a.houseno');
{query1.sql.add('union all ');
//组装出库
query1.sql.add('select b.wareno,a.houseno,-sum(b.curr) as curr,-sum(b.amount) as amount,1 as tag');
query1.sql.add('from waremakeh a,waremakem b where a.period="'+seekdate+'" and a.period=b.period and a.noteno=b.noteno');
query1.sql.add('group by b.wareno,a.houseno');
query1.sql.add('union all ');
//拆装出库
query1.sql.add('select a.wareno,a.houseno,-sum(a.curr) as curr,-sum(a.amount) as amount,1 as tag');
query1.sql.add('from waretearh a where a.period="'+seekdate+'" ');
query1.sql.add('group by a.wareno,a.houseno');}
query1.execsql;
query1.sql.clear;
query1.sql.add('select wareno,houseno,sum(amount) as amount,sum(curr) as curr,sum(curr)/sum(amount) as price');
query1.sql.add('from '+tempname);
query1.sql.add('group by wareno,houseno');//
query1.open;
id:=query1.RecordCount;
query1.first;
while not query1.eof do
begin
QueryWaresum.close;
QueryWaresum.ParamByName('period').asstring:=seekdate;
QueryWaresum.ParamByName('wareno').asstring:=query1.fieldbyname('wareno').asstring;
QueryWaresum.ParamByName('houseno').asstring:=query1.fieldbyname('houseno').asstring;
QueryWaresum.ParamByName('amount').asfloat:=query1.fieldbyname('amount').asfloat;
QueryWaresum.ParamByName('price').asfloat:=query1.fieldbyname('price').asfloat;
QueryWaresum.ParamByName('curr').asfloat:=query1.fieldbyname('curr').asfloat;
QueryWaresum.execsql;
query1.next;
Label2.caption:=inttostr(id);
Label2.Update;
dec(id);
end;

...全文
267 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
dalisong 2004-10-26
  • 打赏
  • 举报
回复
乱!
三面来风 2004-10-26
  • 打赏
  • 举报
回复
昏ing......
zyafsca 2004-10-26
  • 打赏
  • 举报
回复
........
比我写的还乱
恐怖!!
头都晕了~~~~~
铁歌 2004-10-26
  • 打赏
  • 举报
回复
delphi程序员都这样干,其实好改的,把SQL CP出来就可以了
windindance 2004-10-13
  • 打赏
  • 举报
回复
靠,这么长又这么乱,没有人帮你看。-_-|
把你的表结构写出来,
然后说你想做什么事情,帮你重新写就好了。
dxlth 2004-10-13
  • 打赏
  • 举报
回复
太可怕了。
General521 2004-10-13
  • 打赏
  • 举报
回复
太可怕了。
guanjm 2004-10-13
  • 打赏
  • 举报
回复
这么长,又乱七八糟,谁会看啊,除非出钱-_-
tiger341 2004-10-12
  • 打赏
  • 举报
回复
怎么跟写文章似的
dqj 2004-10-10
  • 打赏
  • 举报
回复
//组装入库
{Query1.sql.add('union all ');
if pCbtjfs=1 then Query1.sql.add('select a.wareno as wareno,a.houseno,a.notedate,a.amount,a.price,a.curr,6 as tag,0 as id')
else Query1.sql.add('select a.wareno as wareno,"" as houseno,a.notedate,a.amount,a.price,a.curr,6 as tag,0 as id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from waremakeh a,warecode c');
Query1.sql.add('where a.period="'+Period+'"');
Query1.sql.add('and a.wareno=c.wareno and c.costcalctype="1"');
//折缷入库
Query1.sql.add('union all ');
if pCbtjfs=1 then Query1.sql.add('select b.wareno as wareno,a.houseno,a.notedate,b.amount,b.price,b.curr,7 as tag,b.id')
else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,7 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from waretearh a,waretearm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="1"');}

Query1.sql.add('union all ');
//销售出库
if pCbtjfs=1 then Query1.sql.add('select b.wareno as wareno,a.houseno as houseno,a.notedate,b.amount,b.price,b.curr,11 as tag,b.id')
else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,11 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from wareouth a,wareoutm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="2"');
Query1.sql.add('union all ');
//销售退货
if pCbtjfs=1 then Query1.sql.add('select b.wareno as wareno,a.houseno as houseno,a.notedate,b.amount,b.price,b.curr,10 as tag,b.id')
else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,10 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from refundouth a,refundoutm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="2"');
Query1.sql.add('union all ');
//其他出库
if pCbtjfs=1 then Query1.sql.add('select b.wareno as wareno,a.houseno as houseno,a.notedate,b.amount,b.price,b.curr,12 as tag,b.id')
else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,12 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from otherouth a,otheroutm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="2"');
//调出
Query1.sql.add('union all ');
if pCbtjfs=1 then Query1.sql.add('select b.wareno as wareno,a.oldhouseno as houseno,a.notedate,b.amount,b.price,b.curr,13 as tag,b.id')
else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,13 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from warealloth a,wareallotm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="2"');
//盘亏
Query1.sql.add('union all ');
if pCbtjfs=1 then Query1.sql.add('select b.wareno as wareno,a.houseno,a.notedate,b.amount,b.price,b.curr,14 as tag,b.id')
else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,14 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from warecheckh a,warecheckm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno and a.tag=1 and b.amount<0');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="2"');
//组装出库
{Query1.sql.add('union all ');
if pCbtjfs=1 then Query1.sql.add('select b.wareno as wareno,a.houseno,a.notedate,b.amount,b.price,b.curr,15 as tag,b.id')
else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,15 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from waremakeh a,waremakem b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="1"');
//折缷出库
Query1.sql.add('union all ');
if pCbtjfs=1 then Query1.sql.add('select a.wareno as wareno,a.houseno as houseno,a.notedate,a.amount,a.price,a.curr,16 as tag,0 as id')
else Query1.sql.add('select a.wareno as wareno,"" as houseno,a.notedate,a.amount,a.price,a.curr,16 as tag,0 as id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from waretearh a,warecode c');
Query1.sql.add('where a.period="'+Period+'"');
Query1.sql.add('and a.wareno=c.wareno and c.costcalctype="1"');}
dqj 2004-10-10
  • 打赏
  • 举报
回复
//先进先出计算成本
procedure TFormTotalWare.myCalcCost_Xjxc(year,month:word);

var
period,houseno,wareno,period0:string;
amount0,amount,curr,price:currency;
id:integer;
bj:boolean;
begin
LabelMess.Caption:='正在计算先进先出成本,请稍候......';
LabelMess.update;
if Month>1 then period0:=inttostr(Year)+strright(' '+inttostr(Month-1),2)
else period0:=inttostr(year-1)+'12';
period:=inttostr(Year)+strright(' '+inttostr(Month),2);

query1.close;
Query1.sql.clear;
Query1.sql.add('delete warecost where period="'+Period+'"');
Query1.sql.add('and wareno in (select wareno from warecode where costcalctype="2")');
query1.execsql;
//------------------------

query1.close;
Query1.sql.clear;
//期初成本金额------------
if pCbtjfs=1 then Query1.sql.add('select a.wareno as wareno,a.houseno as houseno,"" as notedate,sum(a.amount) as amount,sum(a.curr)/sum(a.amount) as price,sum(a.curr) as curr,0 as tag,0 as id')
else Query1.sql.add('select a.wareno as wareno,"" as houseno,"" as notedate,sum(a.amount) as amount,sum(a.curr)/sum(a.amount) as price,sum(a.curr) as curr,0 as tag,0 as id');
Query1.sql.add('," " as period," " as noteno');
Query1.sql.add('from waresum a,warecode b');
Query1.sql.add('where a.period="'+period0+'"');
Query1.sql.add('and a.wareno=b.wareno and b.costcalctype="2"');
Query1.sql.add('group by a.wareno');
if pCbtjfs=1 then Query1.sql.add(',a.houseno');
Query1.sql.add('union all ');
//采购入库
if pCbtjfs=1 then Query1.sql.add('select b.wareno as wareno,a.houseno as houseno,a.notedate,b.amount,b.price,b.curr,1 as tag,b.id')
else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,1 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from wareinh a,wareinm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="2"');
//采购退货
Query1.sql.add('union all ');
if pCbtjfs=1 then Query1.sql.add('select b.wareno as wareno,a.houseno as houseno,a.notedate,-b.amount,b.price,-b.curr,2 as tag,b.id')
else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,-b.amount,b.price,-b.curr,2 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from refundinh a,refundinm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="2"');
//其他入库
Query1.sql.add('union all ');
if pCbtjfs=1 then Query1.sql.add('select b.wareno as wareno,a.houseno as houseno,a.notedate,b.amount,b.price,b.curr,3 as tag,b.id')
else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,3 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from otherinh a,otherinm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="2"');
//调入
Query1.sql.add('union all ');
if pCbtjfs=1 then Query1.sql.add('select b.wareno as wareno,a.newhouseno as houseno,a.notedate,b.amount,b.price,b.curr,4 as tag,b.id')
else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,4 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from warealloth a,wareallotm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="2"');
//盘盈
Query1.sql.add('union all ');
//if pCbtjfs=1 then
Query1.sql.add('select b.wareno as wareno,a.houseno as houseno,a.notedate,b.amount,b.price,b.curr,5 as tag,b.id');
//else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,5 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from warecheckh a,warecheckm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'" and a.tag=1 and b.amount>0');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="2"');
Query1.sql.add('union all ');
//调价
//if pCbtjfs=1 then
Query1.sql.add('select b.wareno as wareno,a.houseno as houseno,a.notedate,b.amount,b.newprice-b.oldprice as price,b.curr,8 as tag,b.id');
//else Query1.sql.add('select b.wareno as wareno,"" as houseno,a.notedate,b.amount,b.price,b.curr,1 as tag,b.id');
Query1.sql.add(',a.period,a.noteno');
Query1.sql.add('from adjusth a,adjustm b,warecode c');
Query1.sql.add('where a.period=b.period and a.noteno=b.noteno');
Query1.sql.add('and a.period="'+Period+'"');
Query1.sql.add('and b.wareno=c.wareno and c.costcalctype="2"');
dqj 2004-10-10
  • 打赏
  • 举报
回复
if CheckBox2.Checked then
begin
//--------------------------------------------------------
tempname:='#1'+getrandom;
LabelMess.Caption:='正在汇总商品串号,请稍候......';
LabelMess.update;
query1.close;
query1.sql.text:='delete from warebatch where period="'+seekdate+'"';
query1.execsql;
//期初
Query1.close;
query1.sql.clear;
query1.sql.add('select wareno,batchno,amount');
query1.sql.add('into '+tempname);
query1.sql.add('from warebatch where period="'+period+'" and amount<>0');
query1.sql.add('union all ');
//采购
query1.sql.add('select wareno,batchno,1 as amount');
query1.sql.add('from batchlist where period="'+seekdate+'" and type0="0" ');
query1.sql.add('union all ');
//采购退货
query1.sql.add('select wareno,batchno,-1 as amount');
query1.sql.add('from batchlist where period="'+seekdate+'" and type0="2" ');
query1.sql.add('union all ');
//其他入库
query1.sql.add('select wareno,batchno,1 as amount');
query1.sql.add('from batchlist where period="'+seekdate+'" and type0="4" ');
//发货
query1.sql.add('union all ');
query1.sql.add('select wareno,batchno,-1 as amount');
query1.sql.add('from batchlist where period="'+seekdate+'" and type0="1" ');
query1.sql.add('union all ');
//销售退货
query1.sql.add('select wareno,batchno,1 as amount');
query1.sql.add('from batchlist where period="'+seekdate+'" and type0="3" ');
query1.sql.add('union all ');
//其他出库
query1.sql.add('select wareno,batchno,-1 as amount');
query1.sql.add('from batchlist where period="'+seekdate+'" and type0="5" ');
query1.execsql;
query1.close;
query1.sql.clear;
query1.sql.add('select wareno,batchno,sum(amount) as amount');
query1.sql.add('from '+tempname);
query1.sql.add('group by wareno,batchno');//
//query1.sql.add('having sum(amount)<>0');
query1.open;
id:=query1.RecordCount;
query1.first;
while not query1.eof do
begin
wareno:=query1.fieldbyname('wareno').asstring;
batchno:=query1.fieldbyname('batchno').asstring;
QueryWarebatch.close;
QueryWarebatch.ParamByName('period').asstring:=seekdate;
QueryWarebatch.ParamByName('wareno').asstring:=wareno;
QueryWarebatch.ParamByName('batchno').asstring:=batchno;
QueryWarebatch.ParamByName('amount').asfloat:=query1.fieldbyname('amount').asfloat;
QueryWarebatch.execsql;
query1.next;
Label2.caption:=inttostr(id);
Label2.Update;
dec(id);
end;
end;
time1:=time;
LabelMess.Caption:='汇总完成!('+timetostr(time0)+' - '+timetostr(time1)+')';
BitBtnOk.Enabled:=false;
WriteParamBoolean('options','Calced',true);
beep;beep;beep;
LabelMess.update;
Animate1.Active:=false;
end;
sunshareforever 2004-10-10
  • 打赏
  • 举报
回复
up only
robin0925 2004-10-10
  • 打赏
  • 举报
回复
等会再来!!!
yjdn 2004-10-10
  • 打赏
  • 举报
回复
create proc 过程名 参数1,参数2.....
as
begin
上面的SQL语句


end


--楼主想要别人帮你写完出来,估计要出Money了,嘿嘿
zilang 2004-10-10
  • 打赏
  • 举报
回复
Response.write()
RobinHZ 2004-10-10
  • 打赏
  • 举报
回复
你把sql语句先提取出来,这样大段的代码看了费劲。
dqj 2004-10-10
  • 打赏
  • 举报
回复
太长了,总算贴完了。我想改成存储过程哪位能帮帮我
dqj 2004-10-10
  • 打赏
  • 举报
回复
dec(id);
Label2.caption:=inttostr(id);
Label2.update;
end;
table1.first;
//if wareno='00707' then beep;
amount:=0;curr:=0;
while not table1.eof do
begin
if table1.fieldbyname('amount').asfloat>0 then
begin
amount:=amount+table1.fieldbyname('amount').asfloat;
curr:=curr+table1.fieldbyname('amount').asfloat*table1.fieldbyname('price').asfloat;
end;
table1.delete;
end;
queryWarecost.ParamByName('period').asstring:=Period;
queryWarecost.ParamByName('wareno').asstring:=wareno;
queryWarecost.ParamByName('houseno').asstring:=houseno;
if amount>0 then queryWarecost.ParamByName('price').asfloat:=curr/amount
else queryWarecost.ParamByName('price').asfloat:=0;
queryWarecost.execsql;
end;
end;

end;
dqj 2004-10-10
  • 打赏
  • 举报
回复
if amount>0 then
begin
table1.Append;
table1.edit;
table1.fieldbyname('amount').asfloat:=amount;
table1.fieldbyname('price').asfloat:=query1.fieldbyname('price').asfloat;
table1.fieldbyname('curr').asfloat:=amount*query1.fieldbyname('price').asfloat;
table1.post;
end;
end;
query2.close;
query2.sql.clear;
query2.sql.add('update waremakem');
query2.sql.add('set curr=:curr,price=round((:curr)/amount,2)');
query2.sql.add('where id=:id');
query2.parambyname('id').asinteger:=query1.fieldbyname('id').asinteger;
query2.ParamByName('curr').asfloat:=strtofloat(floattostrf(curr,ffFixed,16,2));
query2.execsql;
end;
16:begin //拆缷出库
amount:=query1.fieldbyname('amount').asfloat;
if amount>=0 then
begin
curr:=0;
table1.first;
while not table1.eof and (amount>0) do
begin
table1.edit;
if table1.FieldByName('amount').asfloat>=amount then
begin
curr:=curr+table1.FieldByName('price').asfloat*amount;
table1.FieldByName('amount').asfloat:=table1.FieldByName('amount').asfloat-amount;
amount:=0;
end else
begin
curr:=curr+table1.FieldByName('price').asfloat*table1.FieldByName('amount').asfloat;
amount:=amount-table1.FieldByName('amount').asfloat;
table1.FieldByName('amount').asfloat:=0;
end;
table1.post;
table1.next;
end;
if amount>0 then curr:=curr+amount*table1.FieldByName('price').asfloat;
end else
begin
amount:=-amount;
curr:=0;
table1.first;
while not table1.eof do
begin
if table1.fieldbyname('amount').asfloat>0 then
begin
table1.edit;
table1.FieldByName('amount').asfloat:=table1.FieldByName('amount').asfloat+amount;
table1.fieldbyname('curr').asstring:=floattostrf(table1.fieldbyname('amount').asfloat*table1.fieldbyname('price').asfloat,ffFixed,16,2);
curr:=-amount*table1.fieldbyname('price').asfloat;
amount:=0;
table1.post;
break;
end;
table1.next;
end;
if amount>0 then
begin
table1.Append;
table1.edit;
table1.fieldbyname('amount').asfloat:=amount;
table1.fieldbyname('price').asfloat:=query1.fieldbyname('price').asfloat;
table1.fieldbyname('curr').asfloat:=amount*query1.fieldbyname('price').asfloat;
table1.post;
end;
end;
query2.close;
query2.sql.clear;
query2.sql.add('update waretearh');
query2.sql.add('set curr=:curr,price=round((:curr)/amount,2)');
query2.sql.add('where period=:period and noteno=:noteno');
query2.parambyname('period').asstring:=query1.fieldbyname('period').asstring;
query2.parambyname('noteno').asstring:=query1.fieldbyname('noteno').asstring;
query2.ParamByName('curr').asfloat:=curr;
query2.execsql;
end;}
end;
query1.next;
加载更多回复(5)

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧