mysql 触发器

 

begin
SELECT a.location,a.flag into @loc,@flag FROM workdrawmst a where a.no=new.no;
select count(*) into @c from locstock where  loccode=@loc and stockid=new.stockid;
if @c<1 then
insert into locstock (loccode,stockid,quantity) values (@loc,new.stockid,-@flag*new.qty);
else
update locstock set quantity=quantity-@flag*new.qty where loccode=@loc and stockid=new.stockid;
end if;
end
posted @ 2011-12-14 10:33  Mose  阅读(147)  评论(0编辑  收藏  举报