Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fields in triggers

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello!

I need to print the field value of current updated row.

My trigger looks like:
----------------------------------------
CREATE TRIGGER PrtFldNm ON CONTHIST
FOR UPDATE
AS

BEGIN
PRINT «fieldname»
END
----------------------------------------

My table:
----------------------------------------
USERID
RECID
----------------------------------------

I want print the USERID value


Thanks,

Best Regards.
 

You can print the values that were inserted. However, I recommend against it for production tables because triggers should not return rows.

Use the virtual table "inserted" to find the values inserted or updated.

CREATE TRIGGER PrtFldNm ON CONTHIST
FOR UPDATE
AS
SET NOCOUNT ON
DECLARE @uid int
SELECT @uid=USERID FROM inserted
PRINT @uid

--------------------------------

It would be more efficient just to Select the values inserted.

CREATE TRIGGER PrtFldNm ON CONTHIST
FOR UPDATE
AS
SET NOCOUNT ON
SELECT * FROM inserted

--------------------------------

I also recommend including SET NOCOUNT ON at the start of each trigger. Terry L. Broadbent
Life would be easier if I had the source code. -Anonymous
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top