

DROP PROCEDURE Copiar_OP_DEPOSITSITEDET_AlTemporalProc
GO
CREATE PROCEDURE Copiar_OP_DEPOSITSITEDET_AlTemporalProc
(	@BATNBRDEPOSITSITE	UD_CORRELATIVOS,
	@SITEID		UD_IDSITE,
	@CORRNBR	INT
)
AS
BEGIN
	BEGIN TRAN

	INSERT INTO TMP_OP_DEPOSITSITEDET(CORRNBR,SITEID,DATEPROCE,SEQUENCE,CUSTIDSS,DEPOSITPASSWORD,DATEDEPOSIT,CURYID,CURYRATE,TOTALPEN,TOTALUSD,DEBEHABER,STATUS,USERID)
	SELECT @CORRNBR,SITEID,DATEPROCE,SEQUENCE,CUSTIDSS,DEPOSITPASSWORD,DATEDEPOSIT,CURYID,CURYRATE,TOTALPEN,TOTALUSD,DEBEHABER,STATUS,USERID 
	FROM OP_DEPOSITSITEDET 
	WHERE BATNBRDEPOSITSITE=@BATNBRDEPOSITSITE AND SITEID=@SITEID 

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

	INSERT  INTO 	TMP_OP_NBRDOCSUMMARY(CORRNBR,SITEID,DATEPROCE,SEQUENCE,DOCSUMMARYTYPEID,NBRDOCSUMMARY) 
		SELECT 	@CORRNBR,SITEID,DATEPROCE,SEQUENCE,DOCSUMMARYTYPEID,NBRDOCSUMMARY
		FROM 	OP_NBRDOCSUMMARY
		WHERE 	BATNBRDEPOSITSITE=@BATNBRDEPOSITSITE AND SITEID=@SITEID

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

	COMMIT TRAN 
	RETURN(0)
END 

