Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Trigger to update existing records Expand / Collapse
Author
Message
Posted Thursday, December 20, 2012 6:18 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:27 PM
Points: 14,550, Visits: 38,420
UPDATE [table] SET [col] = [col]

Seriously? that is the trigger body? updating the column to itself, with referencing the INSERTED virtual table?

Remember we are not in your cube looking over your shoulder; we can only help you if you help us by providing the complete, real update command.


there's got to be much much more than you are telling us, because base don what I've seen so far, it seems you are trying to do something like this:
UPDATE PROD 
SET Product_Name_Expiry = getdate()
WHERE Product_Name_Expiry IS NULL

that is the most basic of UPDATE commands, and your trigger must be more complex than the code you pasted, otherwise you wouldn't need a trigger at all.


Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Post #1398938
Posted Friday, December 21, 2012 2:27 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Friday, November 18, 2016 2:29 PM
Points: 592, Visits: 1,330
Lowell (12/20/2012)
UPDATE [table] SET [col] = [col]

Seriously? that is the trigger body? updating the column to itself, with referencing the INSERTED virtual table?


It's not the trigger body... is the sql statement to fire the trigger on the table...

Try changing the AFTER INSERT, UPDATE to FOR INSERT, UPDATE.

The UPDATE table SET col = col should fire the trigger, I use it often when I want to do exactly what your're trying to accomplish..




If you need to work better, try working less...
Post #1399284
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse