I have a sql server "instead of insert" trigger that populates a single column (PromoCode). It all works perfectly, but I don't like the fact I have had to hardcode the columns in actual INSERT statement:
CREATE TRIGGER PopulateOrderPromoCode ON Order
INSTEAD OF INSERT
AS BEGIN
--// Get the Promo Code
DECLARE @PromoCode int;
EXEC GetPromoCode @PromoCode OUTPUT;
--// Insert the order with the new Promo Code
INSERT INTO Order (Id, CustomerId, PromoCode)
SELECT Id, CustomerId, @PromoCode FROM inserted;
END
I would prefer to simply replace the value inside inserted.PromoCode with @PromoCode and then could use:
INSERT INTO Order
SELECT * FROM inserted;
Can this be done?