DROP PROCEDURE CARGA_TMP_IN_COMPETITIONPRICEDET_PROC
GO
CREATE PROCEDURE CARGA_TMP_IN_COMPETITIONPRICEDET_PROC
( 	@SITEID		UD_IDSITE,
	@DATEPROCE	UD_FECHA,
	@COMPETITIONID	CHAR(2),
	@CORRNBR	INT
)
AS
BEGIN
	BEGIN TRAN
	
	DECLARE @INVTIDSKU	UD_IDCORPORATIVO
	DECLARE @CODFAMFUEL	UD_CATEGORY

	DECLARE @STOCKINITIAL	UD_STOCK	
	DECLARE @INQTY		UD_STOCK
	DECLARE @OUTQTY		UD_STOCK
	DECLARE @UNITMEDFUEL	UD_STKUNITID
	
	SET @INQTY=0
	SET @OUTQTY=0
	SET @CODFAMFUEL=(SELECT CATEGORYFUEL FROM OP_SETUP)
	SET @UNITMEDFUEL=(SELECT UNITMEDFUEL FROM OP_SETUP)

	DECLARE CUR_CTRLPRICE	CURSOR	
	FOR 	SELECT INVTIDSKU FROM IN_INVENTORY
		WHERE CLASSID=@CODFAMFUEL
		ORDER BY INVTIDSKU
	OPEN CUR_CTRLPRICE
   	FETCH NEXT FROM CUR_CTRLPRICE INTO @INVTIDSKU

      	WHILE @@FETCH_STATUS=0
        BEGIN    


		INSERT INTO TMP_IN_COMPETITIONPRICEDET(CORRNBR,SITEID,DATEPROCE,COMPETITIONID,INVTIDSKU,SLS_PRICE) 
		VALUES(@CORRNBR,@SITEID,@DATEPROCE,@COMPETITIONID,@INVTIDSKU,0)

    		FETCH NEXT FROM CUR_CTRLPRICE INTO  @INVTIDSKU
        
      	END /* Termina while */

	COMMIT TRAN
  	CLOSE CUR_CTRLPRICE
  	DEALLOCATE CUR_CTRLPRICE

	RETURN(0)
END 

