cdiego

SP_AgregarPuntos de mysql

Feb 24th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.77 KB | None | 0 0
  1. CREATE DEFINER=`TBH997`@`%` PROCEDURE `AgregarPuntos`( puntos INT, _nombre varchar(20), _historial varchar(100))
  2. BEGIN
  3. DECLARE idUsu INT;
  4. IF (exists(select nombre from prueba where nombre=_nombre))
  5. THEN
  6.     update prueba set monedas = monedas + puntos where nombre=_nombre;
  7.    
  8.     select idUsuario into idUsu from prueba where nombre=_nombre;
  9.     insert into historial (idUsuario,log,visible, fecha) values(idUsu, _historial, 1,now());
  10.     select monedas from prueba where nombre=_nombre;
  11. else
  12.     insert into prueba (nombre,monedas) values (_nombre, puntos);
  13.  
  14.     select idUsuario into idUsu from prueba where nombre=_nombre;
  15.     insert into historial (idUsuario,log,visible, fecha) values(idUsu, _historial, 1,now());
  16.     select monedas from prueba where nombre=_nombre;
  17. END IF;
  18.  
  19. END
Advertisement
Add Comment
Please, Sign In to add comment