SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE procedure [dbo].[p_tt_risk_situations_variables]
	@risk_situations_table type_table_id readonly,
	@culture_code ais_code_short
as 
	set nocount on;
	
	select	risv.*, npv.*, npvt.*, 
			risv_capital_formatted = dbo.f_format_variable(risv_capital, risv_fmt_code__capital, @culture_code, pp.pol_currency_code),
			risv_franchise_formatted = dbo.f_format_variable(risv_franchise, risv_fmt_code__franchise, @culture_code, pp.pol_currency_code),
			risv_franchise_maxi_formatted = dbo.f_format_variable(risv_franchise_maxi, risv_fmt_code__franchise_maxi, @culture_code, pp.pol_currency_code),
			risv_franchise_mini_formatted = dbo.f_format_variable(risv_franchise_mini, risv_fmt_code__franchise_mini, @culture_code, pp.pol_currency_code),
			risv_premium_formatted = dbo.f_format_variable(risv_premium, risv_fmt_code__premium, @culture_code, pp.pol_currency_code)
	from ris_variables risv
		inner join @risk_situations_table t on risv.risv_risk_situation_id = t.id
		inner join pr_products_variables prv on risv.risv_variable_id = prv.prdv_variable_id
		inner join ris_risks_situations rrs on rrs.riss_risk_situation_id = t.id
		inner join pol_policies_situations pps on pps.pols_policy_situation_id = rrs.riss_policy_situation_id 
		inner join pol_policies pp on pps.pols_policy_id = pp.pol_policy_id
		inner join nm_products_variables npv on npv.nmpv_variable_code = prv.prdv_variable_code
		inner join nm_products_variables_types npvt on npvt.nmpvt_type_code = npv.nmpv_type_code
	where risv.risv_not_aquired = 0
		


GO
