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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

After insert trigger

Status
Not open for further replies.

nevergiveup01

Programmer
Nov 18, 2008
18
US
Hi, I'm trying to create a trigger that inserts a new record into tblService with the QuoteID from tblServiceQuote when tblServiceQuote.Accepted = true or = 1( it's a bit).. Anyway, I'm struggling and I'm wondering if someone can tell me where I'm going wrong..


CREATE TRIGGER servicequote

AFTER update servicequote
When(ServiceQuote.Accepted=1)
BEGIN
-- Insert record into Service table
INSERT INTO service
( ServiceQuote.quoteid
)
VALUES
( : quoteid,
);
END;
 
CREATE TRIGGER servicequote
ON tblServiceQuote
FOR UPDATE
AS
BEGIN
INSERT INTO tblService (quoteid)
Select quoteid
from inserted
where Accepted=1

)

END
 
One thing you need to see about the solution above that yours did not take into account, is that pwise has written a trigger that will work no matter how many records are inserted. (assuming that tblService has no other required fields) This is something you should always consider when writing a trigger, There are many methods besides the user interface to put data into a table, so all triggers must account for multiple rows being inserted/updated or deleted. There is an extra ) inthe above code though. YOU might want to take it out before trying to run it.



"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top