-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
--	DECLARE @num int
--	EXEC C6MartPeriodico.PL_Intermediari 'F', 'DLRGCM55A14A669Q' , @num OUTPUT
--	SELECT @num AS NumIntermediari
CREATE procedure [C6MartPeriodico].[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	C6MartPeriodico.PATRIMONIO_TERZI
	WHERE RETE = @Rete
		AND COD_FISCALE = @CodiceFiscale		
	)
	RETURN @numeroRighe
END