关于,入库库存的问题啊

NFDSOFT 2005-12-09 01:34:05
现在有3个表(单据头,单据明细,库存)(单据头和明细有ID连接)(明细和库存有编码连接)
当表头增加一条的时候, 更新每条明细在库存的数量
如果以前没有那种库存,我要在库存表增加该产品
如果以前库存有,更新数量

这东西到底怎么做哦,哎,第一次用这玩意
:(说的不知道清楚不,大家看看,有啥问题您说话,给个方案5555
...全文
184 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
dm1cyg 2005-12-12
  • 打赏
  • 举报
回复
用触发器在进货表上,然后把二楼的代码添进去就可以了
create trigger trg1
on 单据明细
for insert,update,delete
as
begin

if exists(select 1 from deleted)
begin
update a
set
库存量=(select sum(数量) from 单据明细 where 编码=a.编码)
from
库存 a
where
exists(select 1 from deleted where 编码=a.编码)
end


if exists(select 1 from inserted)
begin
update a
set
库存量=(select sum(数量) from 单据明细 where 编码=a.编码)
from
单据明细 a
where
exists(select 1 from inserted where 编码=a.编码)
and
exists(select 1 from 库存 where 编码=a.编码)

insert into 库存(编码,库存量)
select
a.编码,sum(a.数量)
from
单据明细 a
where
exists(select 1 from inserted where 编码=a.编码)
and
not exists(select 1 from 库存 where 编码=a.编码)
end
end
go
浩方软件HFWMS 2005-12-11
  • 打赏
  • 举报
回复
这样的话其实没什么,你只要在增加单据的时候,先去判断一下库存中有没有该编码的记录,如果没有就插,else就增加库存数量不就OK了么!
斜杠青年小Q 2005-12-11
  • 打赏
  • 举报
回复
关注中......
add8849 2005-12-10
  • 打赏
  • 举报
回复
友情UP
NFDSOFT 2005-12-09
  • 打赏
  • 举报
回复
重新补充一下:(
现在有3个表(单据头,单据明细,库存)(单据头和明细有ID连接)(明细和库存有编码连接)
当表头审核了以后, 更新每条明细在库存的数量
如果以前没有那种库存,我要在库存表增加该产品
如果以前库存有,更新数量

是已经做好的,在表头审核,审核完成后,更新库存,这样理解容易把,嘿嘿
NFDSOFT 2005-12-09
  • 打赏
  • 举报
回复
TO libin_ftsafe(子陌红尘|潇湘剑公子@dev-club):
老大他们这有个问题啊,他是先增加明细表,在增加了个表头,我要取表头的字段:(
这样取不出来吧
子陌红尘 2005-12-09
  • 打赏
  • 举报
回复
create trigger trg1
on 单据明细
for insert,update,delete
as
begin

if exists(select 1 from deleted)
begin
update a
set
库存量=(select sum(数量) from 单据明细 where 编码=a.编码)
from
库存 a
where
exists(select 1 from deleted where 编码=a.编码)
end


if exists(select 1 from inserted)
begin
update a
set
库存量=(select sum(数量) from 单据明细 where 编码=a.编码)
from
单据明细 a
where
exists(select 1 from inserted where 编码=a.编码)
and
exists(select 1 from 库存 where 编码=a.编码)

insert into 库存(编码,库存量)
select
a.编码,sum(a.数量)
from
单据明细 a
where
exists(select 1 from inserted where 编码=a.编码)
and
not exists(select 1 from 库存 where 编码=a.编码)
end
end
go
NFDSOFT 2005-12-09
  • 打赏
  • 举报
回复
忘了补充一点了,单据头和明细是别的系统已经作的好,他们增加的,
我现在要根据他们增加的单据算出库存哦

27,579

社区成员

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

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