Hi - I need some help with understanding the syntax of a simple Update, Insert Trigger. I have been reading all week and just as soon as I think I have it, the insertion of data fails. I am a student.(not asking you to do my homework) I just need help with a push in the right direction. I will post my code. If you could show me the errors of my way...I would be greatful!
The problem Create a trigger that will update an audit table with information regarding when a product shipped. I can't believe I am stuck on this simple task.
I am using Microsoft SQL 2008 R2 for my query.
I keep getting errors when attempting to insert the date into the product table to test the trigger. Can you see what I have done wrong?
I hate to ask but need to have someone show me so I can learn this! Oh, I have an instructor..Online course. Would like to figure this out on my own therefore I am asking here. Thanks
CREATE TRIGGER Shipping_Audit_Trg ON Products ---Product table is primary table
FOR UPDATE, INSERT
UPDATE ProductAudit ---- ProductAudit table is to contain information related to shipment, returns. itemid, memberid, productid
SET ShippedDate = GETDATE() ---- I want to pull the date that is inserted into the Product table
---SET returneDate = GETDATE() --- I also want to pull the date for any returns if this field is updated
FROM inserted as i
INNER JOIN ProductAudit as pa
on pa.orderID = i.orderID