Hi all,
I would create a trigger to update a field in a table when in another
table a new record is insert

My scenario is

products table
product_id = INTEGER PK
product =  TEXT
stock = INTEGER

transactions table
transaction_id = INTEGER PK
product_id = INTEGER FK
flow = BOOLEAN (0,1)
quantitty = INTEGER
registered = BOOLEAN (0,1)

I've tried 

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

but I got a 
END [ near ".": syntax error ]
It's the right way?
what is wrong?
I've never done before

regards
giuseppe

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to