DROP PROCEDURE OP_TURNVSSIDEInsProc
GO
CREATE PROCEDURE OP_TURNVSSIDEInsProc
(
    @SITEID               UD_IDSITE,
    @DATEPROCE            UD_FECHA,
    @DATESALES	          UD_FECHA,
    @NUMBERTURN           tinyint,
    @SALESPERID           UD_SALESPERSONID,
    @CORRNBR		  INT	
)
AS
BEGIN
	BEGIN TRAN

    	INSERT  INTO OP_TURNVSSIDE(SITEID,DATEPROCE,DATESALES,NUMBERTURN,SALESPERID,SIDE,STATUS)
    	SELECT  @SITEID,@DATEPROCE,@DATESALES,@NUMBERTURN,@SALESPERID,SIDE,0
	FROM 	TMP_TURNSIDE
	WHERE	CORRNBR=@CORRNBR
	    
    	IF (@@error!=0 AND @@ROWCOUNT=0)
    	BEGIN
		RAISERROR  20000 'Error Agregando Caras a Vendedores'
        	ROLLBACK TRAN
        	RETURN(1)
	END

    	COMMIT TRAN
	RETURN(0)
END

EXEC OP_TURNVSSIDEInsProc '57   ','2003/11/01','2003/11/01',1,'GUS                 ',14274


SELECT * FROM TMP_TURNSIDE
SELECT * FROM CURYRATE
