DROP PROCEDURE OP_CTRLFUELPRICEALLUpdProc
GO
CREATE PROCEDURE OP_CTRLFUELPRICEALLUpdProc
(	
	@SITEID		UD_IDSITE,
	@DATEPROCE	UD_FECHA,
	@CORRNBR	INT,
	@USERID		UD_USERID


)
AS
BEGIN
	BEGIN TRAN


	DELETE FROM OP_CTRLFUELPRICE
	WHERE  SITEID=@SITEID AND DATEPROCE=@DATEPROCE	

	IF(@@ERROR!=0 OR @@ROWCOUNT=0)
	BEGIN
		ROLLBACK
		RAISERROR 20000 'Error Eliminando Registros'
		RETURN(1)
	END 


	INSERT 	INTO OP_CTRLFUELPRICE(SITEID,DATEPROCE,INVTIDSKU,SLS_PRICE,CURYID,QTYSALES,STATUS,USERID)
	SELECT  SITEID,DATEPROCE,INVTIDSKU,SLS_PRICE,CURYID,QTYSALES,0,@USERID FROM TMP_OP_CTRLFUELPRICE
	WHERE 	CORRNBR=@CORRNBR
	
	IF(@@ERROR!=0 OR @@ROWCOUNT=0)
	BEGIN
		ROLLBACK
		RAISERROR 20000 'Error Insentando en Registro'
		RETURN(1)
	END 

	COMMIT TRAN
	RETURN(0)
END 