Subject | Re: [firebird-support] How can i update multiple rows after a delete? |
---|---|
Author | Adomas Urbanavicius |
Post date | 2005-11-21T10:43:31Z |
so, add that procedure into you trigger after insert,after delete.. wherever
execute procedure recalculate_sums(new/old.pro_id);
where SP body something like
update stocks set amount =
(
SELECT sum(Quantity) On_Hand
FROM StockControl
WHERE Pro_Id = :Pro_Id
)
where
Pro_Id = :Pro_Id
ps. just make sure about transactions, if two users in same time with
same pro_id will work, I think you'll have to make transactions lock
wait to update correctly.
Fabio Gomes wrote:
execute procedure recalculate_sums(new/old.pro_id);
where SP body something like
update stocks set amount =
(
SELECT sum(Quantity) On_Hand
FROM StockControl
WHERE Pro_Id = :Pro_Id
)
where
Pro_Id = :Pro_Id
ps. just make sure about transactions, if two users in same time with
same pro_id will work, I think you'll have to make transactions lock
wait to update correctly.
Fabio Gomes wrote:
>Just another question,
>
>How can i make a function to update the actual_stock after i delete a row?
>
>This works when i insert a row:
>
>CREATE TRIGGER SCI ACTIVE AFTER INSERT AS
>BEGIN
>UPDATE STOCK
>SET ACTUAL_STOCK = ACTUAL_STOCK + NEW.STOCK_ADDED
>WHERE PRO_ID = NEW.PRO_ID;
>END
>
>I want to make something like it:
>
>SELECT Pro_Id, sum(Quantity) On_Hand
>FROM StockControl
>WHERE Pro_Id = :Pro_Id
>
>I think that i need to make a function that actived after i delete
>something, than it sum all the stock for that product and write it on the
>actual_stock on the other table.
>
>is there some way to do it?
>
>Thanks guys :)
>
>
>[Non-text portions of this message have been removed]
>
>
>
>
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>Visit http://firebird.sourceforge.net and click the Resources item
>on the main (top) menu. Try Knowledgebase and FAQ links !
>
>Also search the knowledgebases at http://www.ibphoenix.com
>
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
>