create trigger tri_asb
on asb for insert
as
begin
declare @rk int
declare @ck int
declare @sid varchar(20)
select @sid=
商品代碼 ,@rk =入庫數量,@ck=出庫數量 from inserted
if not exists(select * from asb where
商品代碼=@sid)
insert into bsb(
商品代碼,數量) values(@sid,@rk-@ck)
else
update bsb set 數量=數量+(@rk-@ck) where 商品代碼=@sid
end
