DROP PROCEDURE Reporte_Cliente_TPC_Proc
GO
CREATE PROCEDURE Reporte_Cliente_TPC_Proc
(	@CUSTIDSS	UD_CODCLIENT,
	@PRCLVLCUSTID	UD_PRCLVLCUSTID,
	@FLAG		BIT	-- 1 SI SE REQUIERE TPCs POR CLIENTE,0 SI SE REQUIERE CLIENTES POR TPC 
)  
AS
BEGIN

	IF(@FLAG=0)
		BEGIN

			SELECT OP_CUSTOMER_PRCLVL.CUSTIDSS as Codigo,CUSTNAME as Descripcion 
			FROM OP_CUSTOMER_PRCLVL JOIN CUSTOMER 
			ON OP_CUSTOMER_PRCLVL.CUSTIDSS=CUSTOMER.CUSTIDSS
        		WHERE PRCLVLCUSTID=@PRCLVLCUSTID
		END
	ELSE
		BEGIN

			SELECT DISTINCT PRCLVLCUSTID as Codigo,DESCR as Descripcion
       		 	FROM OP_PRCLVLCUST
		       	WHERE PRCLVLCUSTID IN (SELECT OP_CUSTOMER_PRCLVL.PRCLVLCUSTID FROM OP_CUSTOMER_PRCLVL WHERE CUSTIDSS=@CUSTIDSS)
		END 
END     