print in trigger

  • I have the following updatetrigger with a print statement in it but the message never appears. Any ideas why?????

    CREATE TRIGGER [calcfactor] ON [dbo].[ttarget_defaults]

    AFTER UPDATE

    AS

    IF NOT UPDATE(factor)

    begin

    DECLARE @METHOD NVARCHAR(15),

    @MATRIX NVARCHAR(1),

    @CONVFACTOR FLOAT,

    @INITIAL FLOAT,

    @FINAL FLOAT,

    @UNITS_INITIAL NVARCHAR(10),

    @UNITS_FINAL NVARCHAR(10),

    @ONCOL_UNITS_NUM NVARCHAR(10),

    @ONCOL_UNITS_DEN NVARCHAR(10),

    @UNITS_NUM NVARCHAR(10),

    @UNITS_DEN NVARCHAR(10),

    @FACTOR1 FLOAT,

    @FACTOR2 FLOAT,

    @FACTOR3 FLOAT,

    @ERRMSG NVARCHAR(400)

    SELECT @METHOD = A.METHOD, @MATRIX = A.MATRIX, @INITIAL = A.INITIAL,

    @FINAL = A.FINAL, @UNITS_INITIAL = A.UNITS_INITIAL, @UNITS_FINAL = A.UNITS_FINAL,

    @ONCOL_UNITS_NUM = A.ONCOL_UNITS_NUM, @ONCOL_UNITS_DEN = A.ONCOL_UNITS_DEN,

    @UNITS_NUM = A.UNITS_NUM, @UNITS_DEN = A.UNITS_DEN

    FROM INSERTED A

    IF NOT EXISTS (SELECT A.FACTOR

    FROM TCONVERSION A

    WHERE (A.STARTUNITS = @UNITS_FINAL) AND (A.ENDUNITS = @ONCOL_UNITS_DEN))

    BEGIN

    SELECT @ERRMSG = 'No entry in conversion table for start units: ' + @UNITS_FINAL + ' and end units: ' + @ONCOL_UNITS_DEN + '.'

    PRINT 'PRINT THIS'

    RETURN

    END

    UPDATE ttarget_defaults

    SET factor = 2

    WHERE (method = @METHOD) AND (matrix = @MATRIX)

    end

  • Print does not work in triggers as it does not return to the user interface. To handle this look at using RAISERROR.

    Ex.

    Replace

    PRINT 'PRINT THIS'

    with

    RAISERROR ('Error Message', 11, -1)

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply