
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[p_grid_pr_products]
	@product_code AS ais_code_short = '%',
	@branch_id int = 0
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
	WHERE	( @product_code = '%' OR prd_product_code = @product_code )
	and		exists (	select	1 
						from	pr_products_branches
						where	prdb_product_code = prd_product_code
						and		@branch_id in (0, prdb_branch_id)
			)

END

GO
