....
insert into 库存表(编码, 门市, 数量)
select 编码 ,门市 ,0
from inserted
where not exists(
select *
from 库存表
where 库存表.编码 =inserted.编码 and
库存表.门市 =inserted.门市)
update 库存表 set 数量=数量+updt.数量
from 库存表 ,(
select 编码, 门市,sum(数量) "数量"
from (select 编码, 门市,数量
from inserted
union all
select 编码, 门市,-数量
from deleted ) temp
group by 编码, 门市
) updt
where 库存表.编码 =updt.编码 and
库存表.门市 =updt.门市
....
insert into 库存表(编码, 门市, 数量)
select 编码 ,门市 ,0
from inserted
where not exists(
select *
from 库存表
where 库存表.编码 =inserted.编码 and
库存表.门市 =inserted.门市)
update 库存表 set 数量=数量+updt.数量
from 库存表 ,(
select 编码, 门市,sum(数量) "数量"
from (select 编码, 门市,数量
from inserted
union all
select 编码, 门市,-数量
from deleted ) temp
group by 编码, 门市
) updt
where 库存表.编码 =updt.编码 and
库存表.门市 =updt.门市
....
盼指教.
我试了触发器,非常好,能解决我的问题.
我的前端access,只是在添加记录时会出现写入冲突,提示复制到剪帖板,我只有关闭窗体,再打开,才能下一条记录输入.
而在更新时也有写入冲突,然后复复制到剪帖板.
如果添加库存表中没有的门市或编码,提示"缺少或不正确的键列信息,更新影响到过多的行"
如果删除记录,access会提示"其他用户或应用程序已经删除了该记录或更改了其主键的值".
我检查了库存表数量是正确的.后面三项提示可以不理会,第一坝添加记录时会出现写入冲突,提示复制到剪帖板,我只有关闭窗体,再打开,才能下一条记录输入.太影响录入效力
怎样解决呢?
还有,通过购进表输入,库存数量是加,通过销售表输入库存数量是减。我将销售表的触发器的数量*-1,这对不对?insert into b库存(编码, 门市, 数量)
select 编码 ,门市,0*-1
from inserted
where not exists(
select *
from b库存
where b库存.编码 =inserted.编码 and
b库存.门市 =inserted.门市)
update b库存 set 数量=b库存.数量+updt.数量*-1
from b库存 ,(
select 编码, 门市,sum(数量) "数量"
from (select 编码, 门市,数量
from inserted
union all
select 编码, 门市,-数量
from deleted )as #temp
group by 编码, 门市
) as updt
where b库存.编码 =updt.编码 and
b库存.门市 =updt.门市
但是,调拨表不一样:调拨表:日期 调入门市 调出门市 编码 数量
调入门市 ,库存数量加,调出门市,库存数量减,触发器该如何做?
我第一次接触触发器,太多不懂,望指教。
select 编码, 门市,sum(数量) "数量"
from (select 编码, 门市,数量
from b购进
union all
select 编码, 调入方,数量
from b调拨
union all
select 编码, 调出方,-数量
from b调拨
union all
select 编码, 门市,-数量
from b销售) #temp
group by 编码, 门市
有朋友说这样联合三个表,在记录很多时,调用过程又主要是通过ras,可能对速度,性能有较大影响,所以才考虑用库存表,及时更新.但使用触发器出现添加记录时会出现写入冲突,提示复制到剪帖板,我只有关闭窗体,再打开,才能下一条记录输入.这样肯定无法使用.既然触发器与前端无关,这个问题应是access造成,而高手一般不用access,所以这类问题一般不好咨询,而且我是用access2000的adp,资料很少.希望有access的同好单独交流.因为我只是普通用户,也不想再学其它语言,毕竟我不是程序员.