SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_tt_policies_all_umr]
	@policies_situations_table type_table_id readonly

as
	set nocount on;
	 
	select 	distinct 
			pols_policy_situation_id = pst.id, 
			u.umr_umr_code, 
			u.umr_l1, 
			u.umr_l2, 
			u.umr_l3, 
			risv_umr_value			
	from ris_risks_situations rrs 	
		inner join @policies_situations_table pst on rrs.riss_policy_situation_id = pst.id
		inner join ris_variables rv on rv.risv_risk_situation_id = rrs.riss_risk_situation_id
		inner join pr_products_variables ppv on ppv.prdv_variable_id = rv.risv_variable_id
		inner join nm_umr u on u.umr_umr_code = ppv.prdv_umr_code

GO
