DROP PROCEDURE TMP_OP_PRCLVLCUSTDETDelProc
GO
CREATE PROCEDURE TMP_OP_PRCLVLCUSTDETDelProc
(   @INVTIDSKU UD_IDCORPORATIVO,
    @CORRNBR INT,
    @SITEID	UD_IDSITE
)

AS
BEGIN
    BEGIN TRAN

    IF(@SITEID='') 
	BEGIN  
      		DELETE
      		FROM  TMP_OP_PRCLVLCUSTDET
      		WHERE INVTIDSKU=@INVTIDSKU AND
	    	      CORRNBR=@CORRNBR
    	END 
    ELSE
	BEGIN	
		DELETE 
		FROM TMP_OP_PRCLVLCUSTDET
		WHERE CORRNBR=@CORRNBR AND SITEID=@SITEID

	END 

    IF (@@error!=0)
    BEGIN
        RAISERROR  20002 'Error al Eliminar'
        ROLLBACK TRAN
        RETURN(1)
    
    END

    COMMIT TRAN

    RETURN(0)
END

SELECT * FROM TMP_OP_PRCLVLCUSTDET