DROP PROCEDURE IN_COMPETITIONPRICEDETUpdProc
GO
CREATE PROCEDURE IN_COMPETITIONPRICEDETUpdProc
(	
	@SITEID		UD_IDSITE,
	@DATEPROCE	UD_FECHA,
	@COMPETITIONID 	CHAR(2),
	@CORRNBR	INT
)
AS
BEGIN
	BEGIN TRAN


	DELETE FROM IN_COMPETITIONPRICEDET
	WHERE  SITEID=@SITEID AND DATEPROCE=@DATEPROCE AND COMPETITIONID=@COMPETITIONID	

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


	INSERT 	INTO IN_COMPETITIONPRICEDET(SITEID,DATEPROCE,COMPETITIONID,INVTIDSKU,SLS_PRICE)
	SELECT  SITEID,DATEPROCE,COMPETITIONID,INVTIDSKU,SLS_PRICE
	FROM 	TMP_IN_COMPETITIONPRICEDET
	WHERE 	CORRNBR=@CORRNBR
	
	IF(@@ERROR!=0 OR @@ROWCOUNT=0)
	BEGIN
		ROLLBACK
		RAISERROR 20000 'Error Insentando Registros'
		RETURN(1)
	END 

	COMMIT TRAN
	RETURN(0)
END 

