SQL Joins in triggers

Soldato
Joined
11 Feb 2004
Posts
4,532
Location
Surrey, UK
Is this possible? I know its not very efficient but its something I would like to try out.

Say for example I want to link TableA.Name to TableB.Name and the declared variable is @pay.. would I need something like:

select @pay = Name from inserted inner join TableA.Name on TableB.Name = Name
 
Yes you can. Here's an example


CREATE TRIGGER LowCredit ON Purchasing.PurchaseOrderHeader
AFTER INSERT
AS
DECLARE @creditrating tinyint,
@vendorid int
SELECT @creditrating = v.CreditRating, @vendorid = p.VendorID
FROM Purchasing.PurchaseOrderHeader p INNER JOIN inserted i ON p.PurchaseOrderID =
i.PurchaseOrderID JOIN Purchasing.Vendor v on v.VendorID = i.VendorID
IF @creditrating = 5
BEGIN
RAISERROR ('This vendor''s credit rating is too low to accept new
purchase orders.', 16, 1)
ROLLBACK TRANSACTION
END
 
Back
Top Bottom