the deal is to create trigger(function?) which would send updated value from one table and add to another
example:
table1
column:AccountID and 2 column: Money
table2:
column:AccountID and 2 column: Money
i create something like this:
CREATE TRIGGER money_from_vault
ON table1
FOR UPDATE
AS
DECLARE @Money Int,@AccountID varchar(10)
SELECT @Money = (SELECT Money FROM table1),@AccountID=(SELECT AccountID from table1)
IF(@Money!=0)
BEGIN
update table2 set Money=Money+@Money where AccountID=@AccountID
END
And it should work like that:
if table1.money is updated to non-zero value, function should add to table2.Money value from table1.money. (table2.money=table2.money+table1.money)
Afther this table1.money should = 0
its function created to work on mine game. it`s highly possible that simple updating table1.Money = 0 will not work. The reason is when some player leave vault in game opened the game doesnt allow to change money in it. so this code need to be protected from this becouse it can loop untin player close vault... it would be money=money+@money+money+@money....
i dont know what im doing wrong and i want to learn how to do such tasks for the brighter future of my game
could anyone help me?