create procedure dbo.%PROC% @sid varchar(30) = null .ARGLIST_FILTER as declare @action_id numeric, @user_id numeric, @state_id numeric, @type_id numeric begin set nocount on select @action_id = %ACTION_ID% .CHECK_USER .CHECK_VIEW create table #pays4paymt (id numeric) if @purpose_code in (4011) -- выдача begin insert into #pays4paymt select q.id from tp_pif_queries q, t_items i, t_states s, t_types t where i.id = q.id and i.state_id = s.id and i.type_id = t.id and s.class_id =0 and upper(s.state_code) in ('ED','NOT_PAYMT','PROV') and upper(t.type_code) = 'PIF_PAY_ALLOCATE' and q.type_queries in (1,3) end if @purpose_code in (4014) -- погашение begin insert into #pays4paymt select q.id from tp_pif_queries q, t_items i, t_states s, t_types t where i.id = q.id and i.state_id = s.id and i.type_id = t.id and s.class_id =0 and upper(t.type_code) = 'PIF_PAY_BUY' and ((upper(s.state_code) in ('ED','PROV','WAIT_CRT') and not exists (select 1 from t_paydocs p, .ACTUAL_TABLES where p.pif_pay_id=i.id .ACTUAL_WHERE(p.id))) or upper(s.state_code) in ('CRT_RET')) and q.type_queries in (2,4) end if @purpose_code=4015 -- возврат по отказанным заявкам на размещение begin insert into #pays4paymt select q.id from tp_pif_queries q, t_items i, t_states s, t_types t where i.id = q.id and i.state_id = s.id and i.type_id = t.id and s.class_id =0 and upper(s.state_code) in ('PROV','CANCEL') and upper(t.type_code) = 'PIF_PAY_ALLOCATE' end if @purpose_code=4013 -- возврат выкупа begin insert into #pays4paymt select q.id from tp_pif_queries q, t_items i, t_states s, t_types t where i.id = q.id and i.state_id = s.id and i.type_id = t.id and s.class_id =0 and upper(s.state_code) in ('CRT','CRT_NEXT') and upper(t.type_code) = 'PIF_PAY_BUY' end if @purpose_code in (4020) begin insert into #pays4paymt select q.id from tp_pif_queries q, t_items i, t_states s, t_types t where i.id = q.id and i.state_id = s.id and i.type_id = t.id and s.class_id =0 and upper(s.state_code) in ('CRT','PROV','WAIT_CRT') and upper(t.type_code) = 'PIF_PAY_BUY' end if @purpose_code in (4021) begin insert into #pays4paymt select q.id from tp_pif_queries q, t_items i, t_states s, t_types t where i.id = q.id and i.state_id = s.id and i.type_id = t.id and s.class_id =0 and upper(s.state_code) in ('CRT','PROV') and upper(t.type_code) = 'PIF_PAY_ALLOCATE' end .ARGCONVERT_FILTER .VIEW_LIST and exists (select 1 from #pays4paymt where #pays4paymt.id=tp_pif_queries.id) end