I am looking for a solution to maintain a "quantities remaining" type of column in my database. I have constructed a solution in my application code, but I thought perhaps a trigger would be more appropriate. I need to basically do the following:
The @SubCatID parameter is the value of the primary key of the SubCat05 table. Can I accomplish this using a trigger?
Code:
UPDATE SubCat05
SET QuanRemain = (SELECT quantity FROM SubCat05 WHERE SubCatID = @SubCatID) - (SELECT SUM(quan) FROM POSubCat WHERE SubCatID = @SubCatID)
The @SubCatID parameter is the value of the primary key of the SubCat05 table. Can I accomplish this using a trigger?