DROP PROCEDURE TMP_OP_CTRLFUELDETUpdProc
GO
CREATE PROCEDURE TMP_OP_CTRLFUELDETUpdProc
(	@CORRNBR	INT,
	@SITEID		UD_IDSITE,
	@DATEPROCE	UD_FECHA,
	@INVTIDSKU	UD_IDCORPORATIVO,
	@STOCKINITIAL	UD_STOCK,
	@QTYIMPUT	UD_STOCK,
	@QTYOUTPUT	UD_STOCK,
	@QTYSALES	UD_STOCK,
	@QTYAVAIL	UD_STOCK,
	@STKUINITID	UD_STKUNITID,
	@VALUEUNIMED	NUMERIC(7,4),
	@QTYPHISICAL	UD_STOCK,
	@QTYDIFFERENCE	UD_STOCK,
	@PORCENTDIFERENCE UD_PORCENTAJE,
	@REMARK		UD_DESCRIPCION
)
AS
BEGIN
	BEGIN TRAN



	UPDATE	TMP_OP_CTRLFUELDET
	SET 	STOCKINITIAL=@STOCKINITIAL,
		QTYIMPUT=@QTYIMPUT,
		QTYOUTPUT=@QTYOUTPUT,
		QTYSALES=@QTYSALES,
		QTYAVAIL=@QTYAVAIL,
		STKUINITID=@STKUINITID,
		VALUEUNIMED=@VALUEUNIMED,
		QTYPHISICAL=@QTYPHISICAL,
		QTYDIFFERENCE=@QTYDIFFERENCE,
		PORCENTDIFERENCE=@PORCENTDIFERENCE,
		REMARK=@REMARK
	WHERE 	SITEID=@SITEID AND DATEPROCE=@DATEPROCE AND INVTIDSKU=@INVTIDSKU AND CORRNBR=@CORRNBR


	IF(@@ERROR!=0 OR @@ROWCOUNT=0)
	BEGIN
		ROLLBACK
		RAISERROR 20000 'Error Actualizando en Temporal'
		RETURN(1)
	END 


	COMMIT TRAN
	RETURN(0)
END 

SELECT * FROM TMP_OP_CTRLFUELDET

DELETE FROM TMP_OP_CTRLFUELDET