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 --.EXIT_MESSAGE_PARM('@type_id_s', @type_id_s) --.EXIT_MESSAGE_PARM('@owner_id_s', @owner_id_s) .ARGCONVERT_FILTER ---.VIEW_LIST declare @id numeric, @owner_id numeric if @owner_id_s is null select @owner_id= .ORG_FROM_PARTNER(.ORGANIZATION) else select @owner_id = convert(numeric, @owner_id_s) --.EXIT_MESSAGE_PARM('@owner_id', @owner_id) select @id = convert(numeric,@sid) select sid = convert(varchar, t_items.id), state_sid = convert(varchar, t_items.state_id), type_sid = convert(varchar, t_items.type_id), t_items.item_name , t_items.item_remark , state_name=(select t_states.state_name from t_states where t_states.id=t_items.state_id), type_name=(select t_types.type_name from t_types where t_types.id=t_items.type_id), convert(varchar(30),tb_contracts.client_id) as partner_id_s, t_partners.partner_name from #state_list, t_items, td_depo_docs, tb_contracts, t_partners where #state_list.state_id = t_items.state_id and td_depo_docs.id=t_items.id and t_items.id = tb_contracts.id and t_partners.id=tb_contracts.client_id -- and (td_depo_docs.owner_id = (select partner_id from tb_broker_change where id = @owner_id) or (@owner_id_s is null)) and td_depo_docs.owner_id = (select partner_id from tb_broker_change where id = @owner_id) and (isnull(upper(ltrim(rtrim(t_items.item_remark))),'') LIKE isnull('%'+upper(ltrim(rtrim(@item_remark))) + '%','%')) and (tb_contracts.contr_code between @contr_code_bb and @contr_code_bb or @contr_code_nn is null) and (tb_contracts.client_id between @client_id_bb and @client_id_ee or @client_id_nn is null) and (tb_contracts.dogexec_begin_date between @dogexec_begin_date_bb and @dogexec_begin_date_ee or @dogexec_begin_date_nn is null) and (tb_contracts.dogexec_end_date between @dogexec_end_date_bb and @dogexec_end_date_ee or @dogexec_end_date_nn is null) and (td_depo_docs.in_date between @in_date_bb and @in_date_ee or @in_date_nn is null) and (td_depo_docs.document_form_id between @document_form_id_bb and @document_form_id_ee or @document_form_id_nn is null) and (td_depo_docs.in_no between @in_no_bb and @in_no_ee or @in_no_nn is null) and (td_depo_docs.folder_id between @folder_id_bb and @folder_id_ee or @folder_id_nn is null) union select sid = convert(varchar, t_items.id), state_sid = convert(varchar, t_items.state_id), type_sid = convert(varchar, t_items.type_id), t_items.item_name , t_items.item_remark , state_name=(select t_states.state_name from t_states where t_states.id=t_items.state_id), type_name=(select t_types.type_name from t_types where t_types.id=t_items.type_id), convert(varchar(30),tb_broker_change.partner_id) as partner_id_s, t_partners.partner_name from #state_list, t_items, tb_broker_change, t_partners where #state_list.state_id = t_items.state_id and tb_broker_change.id = t_items.id -- and tb_broker_change.partner_id = @owner_id and tb_broker_change.id = @owner_id -- and ((tb_broker_change.id = @owner_id) or (@owner_id_s is null)) and t_partners.id=tb_broker_change.partner_id and (isnull(upper(ltrim(rtrim(t_items.item_remark))),'') LIKE isnull('%'+upper(ltrim(rtrim(@item_remark))) + '%','%')) end