SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[p_grid_pr_products_auth]	
	@user_code		ais_code_medium,			-- id de l'utilisateur connecté (ou '%')
	@introducer_id	int,						-- id de l'apporteur attaché à l'utilisateur connecté (ou 0)
	@branch_id int = 0,
	@product_code AS ais_code_short = '%'
AS
BEGIN
	
	SELECT	prd_product_code, prd_l1, prd_l2, prd_l3, pf_type_pol_code, pf_delegation, pf_bonus
	FROM	dbo.pr_products pp
				inner join pr_families pf on pf.pf_family_code = pp.prd_family_code
				inner join dbo.f_pr_products(@branch_id, @user_code, @introducer_id, '%', getdate()) fct on pp.prd_product_code = fct.product_code
	WHERE	( @product_code = '%' OR prd_product_code = @product_code )


END

GO
