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;

解决方案 »

  1.   

    本人也明白这个道理,但是我们公司现在用的ERP是金蝶K3,至于怎么在程序里写,我自己都不是很清楚,还请各位大哥能帮帮小弟,谢谢!!
      

  2.   

    本人代码如下:
    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