SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[p_grid_act_banks_branch]
	@branch_id	as int,
	@bank_id	as varchar(15) = '%'
AS


/*
	DGE 13/02/2017
	Liste des banques d'une entité juridique.
*/
set nocount on

declare @id int 

if @bank_id = '%'
	set @id = 0
else
	set @id = convert(int, @bank_id)



select	v.*
from	vw_act_banks v
		inner join	(
					select	distinct a.acc_bank_id
					from	act_branches b 
							inner join act_accounts a	on	a.acc_actor_id = b.br_actor_id
					where	b.br_actor_id = @branch_id
					) as t on t.acc_bank_id = v.act_actor_id

where	@id = 0 or v.act_actor_id = @id
		


GO
