BEGIN TRY
-- RAISERROR with severity 11-19 will cause exeuction to
-- jump to the CATCH block.
RAISERROR ('Error raised in TRY block.', -- Message text.
16, -- Severity.
1 -- State.
);
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT; SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE(); -- Use RAISERROR inside the CATCH block to return error
-- information about the original error that caused
-- execution to jump to the CATCH block.
RAISERROR (@ErrorMessage, -- Message text.
@ErrorSeverity, -- Severity.
@ErrorState -- State.
);
END CATCH;
-- RAISERROR with severity 11-19 will cause exeuction to
-- jump to the CATCH block.
RAISERROR ('Error raised in TRY block.', -- Message text.
16, -- Severity.
1 -- State.
);
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT; SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE(); -- Use RAISERROR inside the CATCH block to return error
-- information about the original error that caused
-- execution to jump to the CATCH block.
RAISERROR (@ErrorMessage, -- Message text.
@ErrorSeverity, -- Severity.
@ErrorState -- State.
);
END CATCH;
alter TRIGGER tr_icstockentry
ON icstockbillentry
FOR INSERT,update
AS
declare @prm_errms varchar(255)
if exists
(
select
t5.fnumber
from
ppbom t1 join ppbomentry t2 on t1.finterid = t2.finterid
join icmo t3 on t1.ficmointerid = t3.finterid
join inserted t4 on t4.ficmointerid = t2.ficmointerid and t4.fitemid = t2.fitemid
join t_icitem t5 on t5.fitemid = t2.fitemid
where
t3.fstatus <> 3
and (t2.fauxqtymust - t2.fauxstockqty - t4.fauxqty) < 0
)
begin
RAISERROR ('超过计划投料数量', 16,1)
end