-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [C6Mart].[PL_Intermediari] 
	-- Add the parameters for the stored procedure here
	-- Add the parameters for the stored procedure here
	@Rete char(1), 
	@CodiceFiscale varchar(16),
	@numeroRighe as int OUTPUT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET  @numeroRighe = 
	(SELECT
        COUNT(DISTINCT INTERMEDIARIO)
	FROM	C6Mart.PATRIMONIO_TERZI
	WHERE RETE = @Rete
		AND COD_FISCALE = @CodiceFiscale		
	)
	RETURN @numeroRighe
END