Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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 @ 8:02 AM
Points: 12,962, Visits: 32,505
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
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, December 19, 2014 10:10 AM
Points: 526, Visits: 1,163
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