Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

T-SQL: Problems to using CONTEXT_INFO to bypass Update Trigger processing

$
0
0

SQL Ver:  2008 R2

Problem: I having problems getting CONTEXT_INFO to work properly.  I'm trying to run a stored procedure (SP1) which runs an UPDATE statement on records in Table1.  Table 1 has an Update Trigger (trg_Table1_Update).  When I run SP1, I want to bypass the UPDATE Trigger.  In other words, I don't want "trg_Table1_Update" to Execute. 

The following code template, which uses CONTEXT_INFO, is what I am using and it doesn't seem to be bypassing the trigger execution. 

Any help would be appreciated.

RELATED CODE TEMPLATE:

1. PLACE IN UPDATE TRIGGER AT BEGINNING OF TRIGGER PROCESSING:
  BEGIN  --TRIGGER PROCESSING
  DECLARE @CONTEXT_INFO varbinary(128),@SPID int
  --call system Function to get context info
   SELECT @CONTEXT_INFO = CONTEXT_INFO()
  --Cast the binary data to plain text
   select CAST(@CONTEXT_INFO as varchar(128))
  --Joining with Inserted Table to  update InsertedApplication column
  
  IF CAST(@CONTEXT_INFO as varchar(128)) <> 'usp_EEOTrackingHours' OR @CONTEXT_INFO IS NULL
  BEGIN  -- TRIGGER PROCESSING
   --TRIGGER CODE HERE
  END     --END TRIGGER PROCESSING
  --NOTE:  NO END OR ELSE REQUIRED HERE
  END  --TRIGGER PROCESSING
 
 2. PLACE IN STORED PROCEDURE:
  BEGIN --SP
  
  --SET CONTEXT_INFO VARIABLE TO BY PASS UPDATE TRIGGER
  DECLARE
   @CONTEXT_INFO varbinary(128)
   SELECT @CONTEXT_INFO = cast('usp_EEOTrackingHours' + space(128) as binary(128))
   
   --Set the CONTEXT_INFO with the storedprocedure name
   SET CONTEXT_INFO @CONTEXT_INFO
  
   BEGIN --STORED PROCEDURE CODE


Bob Sutor


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>