Ver Mensaje Individual
  #4  
Antiguo 17-11-2011
abelg abelg is offline
Miembro
 
Registrado: jul 2004
Posts: 50
Reputación: 20
abelg Va por buen camino
Mira esto, espero te sirva.
Código SQL [-]
create trigger NuevoDetalle on Detalles for insert as
begin
    if @@RowCount = 1
      update Articulos
      set Pedidos = Existencias - Cantidad
      from Inserted
      where Articulos.Codigo = Inserted.RefArticulo
    else
      update Articulos
      set Pedidos = Existencias -
          (select sum(Cantidad)
          from Inserted
          where Inserted.RefArticulo=Articulos.Codigo)
      where Codigo in
        (select RefArticulo
        from Inserted)
end
La variable global predefinida @@RowCount indica cuántas filas han sido afectadas por la última operación

Salu2

Última edición por abelg fecha: 17-11-2011 a las 14:32:54.
Responder Con Cita