SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[p_grid_acc_currencies_trnb]
	@payment_code	AS ais_code_short ,
	@currency_code	AS ais_code_short = '%'
AS
BEGIN
	SET NOCOUNT ON;
	
	SELECT	cur_currency_code, 
			cur_l1, 
			cur_l2, 
			cur_l3,
			cur_use_decimals
	FROM	dbo.acc_currencies c
	WHERE	(@currency_code = '%' OR cur_currency_code = @currency_code)
	AND		EXISTS	(	SELECT	1
						FROM	dbo.acc_transactions t 
								INNER JOIN dbo.acc_accounts a ON a.a_account_id = t.atrn_transaction_id
						WHERE	t.atrn_payment_code = @payment_code
						AND		a.a_currency_code = c.cur_currency_code
						AND		NOT EXISTS(	SELECT	1
											FROM	dbo.acc_trn_bordereaux_details d
											WHERE	d.trnbd_transaction_id = t.atrn_transaction_id) 
					)

	
END
GO
