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!

How do I change a value in an Inserttrigger? 1

Status
Not open for further replies.

dakle

Programmer
Jul 30, 2001
6
SE
Hi!

I have a trigger for insert where I want to change one of the values that are inserted. The value is a datetime which I want to withdraw one day from. I will do that by:

SELECT @TempVal = (SELECT @Val FROM INSERTED)

SELECT @NewVal = DATEADD(day, -1, @TempVal)

But how do I finish the insert that started the trigger?
Do I write a new separate insert in the trigger to insert the new post or do I modify the original post before complition of the insert?

Anyone who can help me?

Regards David
 
Hi David,
If always you want to withdraw one day from the inserted date, it is better to do in front end.
By the way in the trigger you can do the same by writing statement :
CREATE TRIGGER myInsTrigger ON myTable FOR INSERT AS
UPDATE myTable
SET myDateValue=DATEADD(day, -1, i.myDateValue)
FROM myTable a, inserted i
WHERE a.KeyColumn(s)=i.KeyColumn(s)


Don't forget to put the KeyColumn(s) condition. Otherwise the update statement may update unnecessary data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top