On 3/16/2012 11:59 AM, Giuseppe Costanzi wrote:
CREATE TRIGGER update_stocks AFTER INSERT ON transactions
BEGIN
UPDATE products
SET
products.stock =(CASE
WHEN (transactions.flow =1 )
THEN SUM(products.stock +
transactions.quantity)
ELSE SUM(products.stock -
transactions.quantity)
END)
WHERE products.product_id = transactions.product_id
AND transactions.registered =1;
END
CREATE TRIGGER update_stocks AFTER INSERT ON transactions
BEGIN
UPDATE products SET stock =
(CASE WHEN new.flow = 1
THEN stock + new.quantity
ELSE stock - new.quantity
END)
WHERE product_id = new.product_id
AND new.registered =1;
END;
--
Igor Tandetnik
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users