如何使用存储过程interbase从 2 个表中删除记录

问题描述

我在 interbase 2009 db 中有 2 个 master-detail 表:Master table Tincome 用于有关商品收入的数据和 Toincome 表用于销售记录:

收入:in_id (pr_k)、indate、qnt
结果:out_id(pr_k),in_id (fk),outdate,qnt

我必须从明细表(tOutcomes)删除销售日期(TIncomes)。 如果此时(01.01.2018)还有剩余货物,那么我对收入表的记录不做任何处理,而是删除部分结果(销售)记录(仅在 outdate

enter image description here

create procedure sp_del_out_in (d date)
as
begin
for select i.in_id
from tIncome i,tOutcome o
where
 (i.qnt-(select sum(o.qnt) from tOutcome o where outdate<:d)<0.001) and
 (i.in_id=o.in_id)
into :in_id 
do 
begin
  delete from tOutcome where in_id = :in_id;
  delete from tIncome where in_id = :in_id;
end
end

程序主体

select i.in_id
from tIncome i,tOutcome o
where
 (i.qnt-(select sum(o.qnt) from tOutcome o where outdate<'01/01/2018')<0.001) and
 (i.in_id=o.in_id)
    

未正常工作,因为查询返回结果 where are records with in_id= 15984 where outdate>01.01.2018.

enter image description here

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)