SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Trigger to update existing records


Trigger to update existing records

Author
Message
Lowell
Lowell
One Orange Chip
One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)

Group: General Forum Members
Points: 29114 Visits: 39984
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!

PiMané
PiMané
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1076 Visits: 1334
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...
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search