Ver Mensaje Individual
  #2 (permalink)  
Antiguo 13/07/2010, 17:28
Avatar de flaviovich
flaviovich
 
Fecha de Ingreso: agosto-2005
Ubicación: Lima, Peru
Mensajes: 2.951
Antigüedad: 18 años, 9 meses
Puntos: 39
Respuesta: Ayuda con Trigger - Sintaxis

Prueba asi:
Código SQL:
Ver original
  1. CREATE TRIGGER actsaldo ON detmovimiento
  2. FOR UPDATE
  3. AS
  4. BEGIN
  5.  
  6. DECLARE @tipo AS SMALLINT
  7. DECLARE @insumo AS INTEGER
  8. DECLARE @oldcantidad AS NUMERIC
  9. DECLARE @newcantidad AS NUMERIC
  10.  
  11. SELECT @tipo = tipomovimiento,@insumo = idinsumo,@oldcantidad = cantmovimiento
  12. FROM deleted
  13.  
  14. SELECT @newcantidad = cantmovimiento
  15. FROM inserted
  16.  
  17. IF UPDATE (cantmovimiento)
  18.     IF @tipo= 1
  19.         UPDATE saldo SET entradas = (entradas - @oldcantidad) + @newcantidad, saldos = (saldos - @oldcantidad) + newcantidad
  20.         WHERE idinsumo= @insumo
  21.     ELSE
  22.         UPDATE saldo SET salidas = (salidas - @oldcantidad) + @newcantidad,saldos = (saldos + @oldcantidad) - @oldcantidad
  23.         WHERE idinsumo= @insumo
  24.  
  25. END
__________________
No repitamos temas, usemos el Motor de busquedas
Plantea bien tu problema: Ayúdanos a ayudarte.