Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mdelgado
Posting Yak Master
141 Posts |
Posted - 2003-04-11 : 14:40:48
|
| I need some help in creating a trigger.I currently have a table that contains all the shipped information for our company. Our company has both US and Canadian divisions. The division number for Canada is 99.I have a DTS package that runs evernight that takes the previous 10 days shipped info. from a flat file and deletes any current records that in the table and insert the previous day.I would like to have a trigger fire evertime there is an insert on the table that takes the PRICE field where DIVISION=99 and multiplies x .66666. However I only want to perform this on any NEW records that are inserted leaving old data alone.Any Ideas? Again, my fear is that I will accidentally update records after they have already been updated.thanks. |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-04-11 : 14:49:06
|
| TRIGGERS are separated in to three functional groups. INSERT, UPDATE and DELETE.If you can a trigger for INSERT, any existing rows will not be affected.But if you're still worried about it, make a process that will copy all your existing rows to a holding table before you perform the Insert. You also have to coorelate (I Think) to the Inserted virtual table.CREATE TRIGGER [TRIGGER NAME] ON [dbo].[Table_Name] FOR INSERTASUPDATE Table_Name o Set Amount = Amount *.66666WHERE Exists (SELECT 1 FROM Inserted i Where o.key = i.key)GoI think that'll work.Brett8-) |
 |
|
|
|
|
|