需求:
代加工企业收取客户材料代加工,系统建立无核算成本仓库用于专门存放客供料,杜绝在系统中做调拨单,在客供料仓库进行调拨,导致成本混乱
解决方案

通过在调拨单主表建立触发器,识别到客供仓,自动禁止审核并进行提示
create trigger TransVouch0001
on TransVouch
for update as
if Update(cVerifyPerson) begin
declare
@转入仓库 nvarchar(20),
@审核人 nvarchar(20),
@转出仓库 nvarchar(20);
set @转入仓库 =(select
TransVouch.cIWhCode
from TransVouch,inserted
where inserted.ID=TransVouch.id );
set @转出仓库 =(select
TransVouch.cOWhCode
from TransVouch,inserted
where inserted.ID=TransVouch.id );
set @审核人=(select inserted.cVerifyPerson from TransVouch,inserted
where inserted.id=TransVouch.id)
set nocount on
if ISNULL(@审核人,'')=N'null'
begin
set nocount off
return
end
if ISNULL(@审核人,'')<>N'null'
begin
if exists (select * from inserted
inner join TransVouch on inserted.id=TransVouch.id
and ( @转出仓库=801 or @转入仓库 =801)and @审核人 is not null)
raiserror('友情提示:检查转入转出仓库,客供料仓不参与调拨!',16,0)
end
set nocount off
end