0

I am writing a trigger for controlling a field. The script works as I want but my problem is in the raiseerror. I want the trigger to work without showing the error message to the user.

Can anyone who knows what is the equivalent of raiseerror without showing the error message to the user.

DECLARE @val varchar(9)
SELECT @val= [DC_Piece] 
from INSERTED 
where INSERTED [DC_Domaine]=0 and INSERTED.[DC_IdCol]=6

IF UPDATE([DC_Piece])
BEGIN
    IF NOT EXISTS( select [DO_PIECE] 
    from DOCEN 
    where  @val= [DO_Piece] and [DO_Domaine]=0 and [DO_Type]=6)
        RAISERROR('STOP',11,1)
END
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
hollyx
  • 99
  • 1
  • 9
  • This may help: http://stackoverflow.com/questions/659188/sql-server-stop-or-break-execution-of-a-sql-script – FLICKER Mar 31 '16 at 22:48
  • `RAISERROR` is used to generate error messages and initiate error processing. In your code, it appears that it is only used to generate error message. Can you not just remove the `RAISERROR` block. If you want the trigger to rollback the changes, you can use `ROLLBACK TRANSACTION` instead. – Amit Sukralia Mar 31 '16 at 23:09
  • with rollback transaction i got another message error – hollyx Apr 01 '16 at 08:58
  • Just put your code to a stored procedure CREATE PROCEDURE AS ... and do RETURN instead of the RAISERROR, which will silently stop and return. – Avi Nov 29 '19 at 12:49

0 Answers0