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


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

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


	INSERT 	INTO IN_COMPETITIONPRICE(SITEID,DATEPROCE,INVTIDSKU,PRICESUGGESTED,PRICECURRENT,PRICEPREVIOUS)
	SELECT  SITEID,DATEPROCE,INVTIDSKU,PRICESUGGESTED,PRICECURRENT,PRICEPREVIOUS
	FROM 	TMP_IN_COMPETITIONPRICE
	WHERE 	CORRNBR=@CORRNBR
	
	IF(@@ERROR!=0 OR @@ROWCOUNT=0)
	BEGIN
		ROLLBACK
		RAISERROR 20000 'Error Insertando Registros'
		RETURN(1)
	END 

	COMMIT TRAN
	RETURN(0)
END 


SELECT * FROM IN_COMPETITIONPRICE