SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_policies_last_situation_incomplete]
    @policy_ids_table type_table_id readonly
as
    set nocount on;

    select pp.pol_policy_id
    from pol_policies pp 
	   inner join @policy_ids_table pit on pit.id = pp.pol_policy_id
	   inner join pol_policies_situations pps on pps.pols_policy_situation_id = pp.pol_last_policy_situation_id
    where pps.pols_incomplete = 1
GO
