create procedure dbo.%PROC% @sid varchar(30) = null .ARGLIST_FILTER as .BEGIN('N') create table #class(stock_id numeric(18,0) null) .CHECK_USER .CHECK_VIEW_LIST .ARGCONVERT_FILTER if @class_flag is null select @class_flag = 0 if @class_flag = 0 begin .VIEW_LIST end else if @class_flag = 1 begin -- По значению классификатора insert into #class(stock_id) select distinct t_item2class.item_id from t_item2class, t_classvalues where t_classvalues.class_id = @class_type_id and t_item2class.value_id = t_classvalues.id --and (t_item2class.value_id=@class_value_id) and t_classvalues.id=@class_value_id --and (t_item2class.value_id between @class_value_id_bb and @class_value_id_ee or @class_value_id_nn is null) .VIEW_LIST and exists(select 1 from #class where #class.stock_id = t_items.id) end else if @class_flag = 2 begin -- По НЕ установленному значению классификатора insert into #class(stock_id) select distinct t_item2class.item_id from t_item2class, t_classvalues where t_classvalues.class_id = @class_type_id and t_item2class.value_id = t_classvalues.id and t_classvalues.id=@class_value_id --and (t_item2class.value_id between @class_value_id_bb and @class_value_id_ee or @class_value_id_nn is null) --and (t_item2class.value_id=@class_value_id) .VIEW_LIST and NOT exists(select 1 from #class where #class.stock_id = t_items.id) end .END