SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[p_grid_pr_families_cies]
	@family_code	as ais_code_short,
	@treaty			as varchar(1) = '%',		-- 1 (seulement les traités)/ 0 (seulement les compagnies qui ne sont pas traités) / % (ttes les compagnies)
	@company_id		varchar(15) = '%'
AS

set nocount on;

declare @id int 

if isnumeric(@company_id) = 1 set @id = convert(int,@company_id)

select	*
from	pr_families_cies 	
		inner join vw_act_cies on prfc_company_id = cie_actor_id
where	prfc_family_code = @family_code 
and		1 =	case
			when @treaty = '%' then 1
			when @treaty = '1' and cie_treaty != 0 then 1
			when @treaty = '0' and cie_treaty = 0 then 1
			else 0
			end
and		( @company_id = '%' OR prfc_company_id = @id)

GO
