I’d do a Stored Procedure
in your mysql command (I think you are using mysql)
the first line of the sql delimiter
DELIMITER $$
CREATE PROCEDURE IF NOT EXISTS addSaldo(IN costumerName VARCHAR(255), IN valor INT)
BEGIN
Select campo seus queries aqui .......
adicione usando variable valor ......
WHERE ...... = costumerName;
END $$
DELIMITER ;
last line trades the delimeter back to ";"
to use the query now
CALL addSaldo("nomeDoCliente", valorASerAdicionado);
using this method you will have better efficiency, better maintenance and more security.
if you want to do outside of mysql command (easy maintenance)
1) create an addSaldo.sql file
2) put the above code inside this file and save
3) run the command (Linux)
mysql -u root -pSenhaDoRoot NomeDaDatabase < addSaldo.sql
ready , if you want to make future change and only change in the file , drop in the previous and run this command.
as I do not know the structure of your table has no way to help you in the format of queries.
Hello, it depends on how are the data in your table, if they are along with text 100€ you will have to treat first removing the text in the querie that can be using replace, then you will have to convert to number and then make the sum, if you are without the text but contain point 100.55 can make the normal sum in the querie itself as friends reported in the answers below.
– Wilson Rosa Gomes
Frankly your question is not clear, exemplify with the current code and what you want to optimize.
– Maurício Júnior