-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [C6Mart].[getCodiceContratto]
	@codiceFiscale as varchar(16),
	@rete as varchar(1),
	@codicePB as varchar(6)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	SELECT DISTINCT
		CodiceContratto
	FROM 
		C6Mart.contrattoSEI c6 
--	JOIN
--		C6Mart.anag_clienti ac
--	ON
--		c6.cod_fiscale = ac.cod_fiscale AND
--		c6.rete = ac.rete
--	JOIN
--		C6Mart.anag_promotori ap
--	ON
--		c6.cod_agente = ap.id_promotore
	WHERE	c6.rete = @rete AND
			c6.cod_fiscale = @codiceFiscale AND
			c6.cod_agente = @codicePB
--	WHERE
--		((@rete is null) or (c6.rete = @rete))  AND
--		((@CodicePB is null) or (c6.Cod_Agente like @codicePB + '%')) AND
--		((@cod_fiscale is null) or (c6.cod_fiscale like @cod_fiscale + '%')) AND
--		((@nomeCliente is null) or (ac.nome like @nomeCliente + '%')) AND
--		((@cognomeCliente is null) or (ac.cognome like @cognomeCliente + '%')) AND
--		((@cognomePB is null) or (ap.cognome like @cognomePB + '%')) AND
--		((@nomePB is null) or (ap.nome like @nomePB + '%'))
END