Ver Mensaje Individual
  #3  
Antiguo 29-10-2008
Avatar de rgstuamigo
rgstuamigo rgstuamigo is offline
Miembro
 
Registrado: jul 2008
Ubicación: Santa Cruz de la Sierra-Bolivia
Posts: 1.646
Reputación: 17
rgstuamigo Va por buen camino
Thumbs up

Claro que se puede:

Código SQL [-]
DELIMITER $$

DROP PROCEDURE IF EXISTS `MIBaseDeDatos`.`Insertar` $$
CREATE PROCEDURE `MIBaseDeDatos`.`Insertar` (cod int,cant int)
BEGIN
   if exists(select Cod from Tabla1 t where t.Cod=cod)then
         update Tabla1 t set Cantidad = Cantidad + cant where t.Cod =cod;
      else
           insert into Tabla1 values (cod, cant);
    end if;
END $$

DELIMITER ;
__________________
"Pedid, y se os dará; buscad, y hallaréis; llamad, y se os abrirá." Mt.7:7

Última edición por rgstuamigo fecha: 29-10-2008 a las 23:50:12.
Responder Con Cita