use [xc]
go
create trigger xc_cfq_项目工程执行中心出库单
ON [dbo].[项目工程执行中心出库单]
After UPDATE
AS
Declare @sl as int
Declare @mc as char
Declare @cur_sl as int
select @sl = sl from inserted
select @mc = mc from inserted
if exists(select sl from [dbo].[库存]
where @sl = sl and mc = @mc)
Begin
select @sl = sl from [dbo].[库存]
where @sl = sl and mc = @mc
if (@cur_sl - @sl begin
delete from [dbo].[库存] where @sl = sl and mc = @mc
end
Else
Begin
Update [dbo].[库存] set sl= (@cur_sl - @sl)
where @sl = sl and mc = @mc
End
end