Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/07/2016, 16:06
jjcx92
 
Fecha de Ingreso: mayo-2015
Mensajes: 11
Antigüedad: 9 años
Puntos: 0
hola buenas tardes amigos quisiera que me ayudaran a hacer que funciones este procedimiento almacenado que revisa si hay suficiente existencia en el inventario si no que le mande un error y le de rollback aqui como lo tengo
Código SQL:
Ver original
  1. USE [BD_FACTURACION]
  2. GO
  3. /****** Object:  StoredProcedure [dbo].[sp_ingresar_detalle]    Script Date: 24/07/2016 7:23:43 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROCEDURE [dbo].[sp_ingresar_detalle]
  9. @numProducto INT,
  10. @Num_venta INT,
  11. @cantidad INT,
  12. @precio money
  13.  
  14. AS
  15. BEGIN
  16. BEGIN tran d
  17. BEGIN try
  18. DECLARE @cantidadi INT
  19. SELECT @cantidadi=existencia FROM Inventario WHERE Num_producto=@numProducto
  20. IF(@cantidadi>@cantidad)
  21. BEGIN
  22. INSERT INTO tblDetalleventa VALUES(@numProducto,@Num_venta,@cantidad,@precio)
  23. UPDATE Inventario SET Existencia=@cantidadi-@cantidad WHERE Num_producto=@numProducto
  24. END
  25. ELSE
  26. raiserror ('no hay suficiente inventario',16,1)
  27.  
  28. ROLLBACK TRAN d
  29. END try
  30. BEGIN catch
  31.  
  32.         ROLLBACK TRAN d
  33. END catch
  34. END

muchas gracias de antemano estoy pegado con ese procedimiento

Última edición por gnzsoloyo; 25/07/2016 a las 09:54