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 |
Vack
Aged Yak Warrior
530 Posts |
Posted - 2008-05-13 : 08:50:57
|
Trying to create a trigger on a table that will delete any records in it that do not exist in another table. Inserting into OrderRebateHistory Table. if ordtype, ord_no, and line_seq_no do not exist in oelinhst then delete from OrderRebateHistory or do not insert. Right now my code will insert the record. Then when another record gets inserted the previous record is deleted. CREATE TRIGGER [DeletefromOrderRebateHistory] ON [dbo].[OrderRebateHistory] for INSERTASDELETE OrderRebateHistoryFROM OrderRebateHistory inner join oelinhst_sql on oelinhst_sql.ord_type = OrderRebateHistory.ord_type andoelinhst_sql.ord_no = OrderRebateHistory.ord_no and oelinhst_sql.line_seq_no = OrderRebateHistory.line_seq_nowhere oelinhst_sql.ord_type <>OrderRebateHistory.ord_type and oelinhst_sql.ord_no <> OrderRebateHistory.ord_noand oelinhst_sql.line_seq_no <> OrderRebateHistory.line_seq_no |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
|
|
|
|