drop procedure if EXISTS autodecrement; delimiter $$ CREATE PROCEDURE autodecrement(IN tableName VARCHAR(50),IN fieldName VARCHAR(20),IN id int,IN action VARCHAR(10),IN step int,OUT result int) BEGIN set @sql = concat('update ',tableName,' set ',fieldName,' = ',fieldName,action,step,' where id = ',id,' and ',fieldName,action,step,' > 0'); prepare stmt from @sql; execute stmt; select ROW_COUNT() into result; END$$ delimiter;