DROP PROCEDURE TMP_OP_CTRLFUELPRICEInsProc
GO
CREATE PROCEDURE TMP_OP_CTRLFUELPRICEInsProc
(	@CORRNBR	INT,
	@SITEID		UD_IDSITE,
	@DATEPROCE	UD_FECHA
)
AS
BEGIN
	BEGIN TRAN

	DECLARE @CODMONEDABASE	UD_CURYID
	DECLARE @CODCATFUEL	CHAR(2)
	SET @CODMONEDABASE=(SELECT CURYORIG FROM SETUP)
	SET @CODCATFUEL=(SELECT CATEGORYFUEL FROM OP_SETUP)
	
	
	INSERT 	INTO TMP_OP_CTRLFUELPRICE(CORRNBR,SITEID,DATEPROCE,INVTIDSKU,SLS_PRICE,CURYID,QTYSALES)
	SELECT @CORRNBR,@SITEID,@DATEPROCE,A.INVTIDSKU,D.SLS_PRICE,@CODMONEDABASE AS CURYID,0
	FROM IN_INVENTORY AS A JOIN IN_INVENTORYDAT AS D
	ON A.INVTIDSKU=D.INVTIDSKU
	WHERE A.CLASSID=@CODCATFUEL AND
	D.SITEID=@SITEID

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

	COMMIT TRAN
	RETURN(0)
END 


SELECT * FROM TMP_OP_CTRLFUELPRICE
DELETE FROM TMP_OP_CTRLFUELPRICE


 EXEC TMP_OP_CTRLFUELPRICEInsProcAutomatico 42889,'57   ','20030318'

 SELECT SITEID AS Almacen,T.INVTIDSKU as Codigo,A.DESCR AS Descripcion, QTYSALES as Gal_Vendidos,SLS_PRICE as Precio_Gal, TOTAL As Monto  FROM TMP_OP_CTRLFUELPRICE AS T JOIN IN_INVENTORY AS A  ON T.INVTIDSKU=A.INVTIDSKU  WHERE CORRNBR=42889