create procedure dbo.%PROC% @sid varchar(30) = null as declare @action_id numeric, @id numeric, @user_id numeric, @state_id numeric, @new_state_id numeric, @type_id numeric select @action_id = %ACTION_ID% select @id = convert(numeric, @sid) .GET_PROPS declare @start_date datetime, --начальная дата @start_srez numeric select @start_srez=@startsrez_id if @srez_date_b is null select @start_date=convert(datetime,'01/01/1800') else select @start_date=@srez_date_b .TRANSACTION_SAVE create table #report( row_code varchar(50) not null, row_name varchar(255) not null, row_sum money null, row_qty decimal(24,10) null ) begin tran declare @plan_id numeric select @plan_id=.ARG_PLAN('PIF_ACCOUNT') if @plan_id is null .EXIT_MESSAGE('Не найден план PIF_ACCOUNT') declare @plan2partner numeric select @plan2partner=(select t_plans2partner.id from t_plans2partner,.ACTUAL_TABLES where t_plans2partner.plan_id=@plan_id and t_plans2partner.partner_id=@fond_id .ACTUAL_WHERE(t_plans2partner.id)) if @plan2partner is null .EXIT_MESSAGE('У фонда нет плана счетов PIF_ACCOUNT') declare @acc_011 numeric, @acc_551 numeric, @acc_581 numeric, @acc_583 numeric, @acc_761 numeric, @acc_7610 numeric, @acc_7611 numeric, @acc_7612 numeric, @acc_7613 numeric, @acc_7614 numeric, @acc_7615 numeric, @acc_7616 numeric, @acc_7617 numeric, @acc_7618 numeric, @acc_762 numeric, @acc_763 numeric, @acc_7641 numeric, @acc_7642 numeric, @acc_7651 numeric, @acc_7652 numeric, @acc_7653 numeric, @acc_7654 numeric, @acc_7655 numeric, @acc_766 numeric, @acc_767 numeric, @acc_768 numeric, @acc_769 numeric, @acc_861 numeric, @acc_862 numeric, @acc_865 numeric, @acc_901 numeric, @acc_902 numeric select @acc_011= .SD_ACCID_FROM_EFFNO(@plan_id,'01.1') select @acc_551= .SD_ACCID_FROM_EFFNO(@plan_id,'76.5.4') select @acc_581= .SD_ACCID_FROM_EFFNO(@plan_id,'58.1') select @acc_583= .SD_ACCID_FROM_EFFNO(@plan_id,'58.3') select @acc_761= .SD_ACCID_FROM_EFFNO(@plan_id,'76.1') select @acc_7610= .SD_ACCID_FROM_EFFNO(@plan_id,'76.10') select @acc_7611= .SD_ACCID_FROM_EFFNO(@plan_id,'76.11') select @acc_7612= .SD_ACCID_FROM_EFFNO(@plan_id,'76.12') select @acc_7613= .SD_ACCID_FROM_EFFNO(@plan_id,'76.13') select @acc_7614= .SD_ACCID_FROM_EFFNO(@plan_id,'76.14') select @acc_7615= .SD_ACCID_FROM_EFFNO(@plan_id,'76.15') select @acc_7616= .SD_ACCID_FROM_EFFNO(@plan_id,'76.16') select @acc_7617= .SD_ACCID_FROM_EFFNO(@plan_id,'76.17') select @acc_7618= .SD_ACCID_FROM_EFFNO(@plan_id,'76.18') select @acc_762= .SD_ACCID_FROM_EFFNO(@plan_id,'76.2') select @acc_763= .SD_ACCID_FROM_EFFNO(@plan_id,'76.3') select @acc_7641= .SD_ACCID_FROM_EFFNO(@plan_id,'76.4.1') select @acc_7642= .SD_ACCID_FROM_EFFNO(@plan_id,'76.4.2') select @acc_7651= .SD_ACCID_FROM_EFFNO(@plan_id,'76.5.1') select @acc_7652= .SD_ACCID_FROM_EFFNO(@plan_id,'76.5.2') select @acc_7653= .SD_ACCID_FROM_EFFNO(@plan_id,'76.5.3') select @acc_7654= .SD_ACCID_FROM_EFFNO(@plan_id,'76.5.4') select @acc_7655= .SD_ACCID_FROM_EFFNO(@plan_id,'76.5.5') select @acc_766= .SD_ACCID_FROM_EFFNO(@plan_id,'76.6') select @acc_767= .SD_ACCID_FROM_EFFNO(@plan_id,'76.7') select @acc_768= .SD_ACCID_FROM_EFFNO(@plan_id,'76.8') select @acc_769= .SD_ACCID_FROM_EFFNO(@plan_id,'76.9') select @acc_861= .SD_ACCID_FROM_EFFNO(@plan_id,'96.1') select @acc_862= .SD_ACCID_FROM_EFFNO(@plan_id,'96.2') select @acc_865= .SD_ACCID_FROM_EFFNO(@plan_id,'86.5') select @acc_901= .SD_ACCID_FROM_EFFNO(@plan_id,'48.1') select @acc_902= .SD_ACCID_FROM_EFFNO(@plan_id,'48.2') /* -- ДЛЯ СТАРОЙ ВЕРСИИ ------------------------------------------- declare @acc_90 numeric, @acc_962 numeric select @acc_90=.SD_ACCID_FROM_EFFNO(@plan_id,'90') select @acc_962=.SD_ACCID_FROM_EFFNO(@plan_id,'89.2') select @acc_901=@acc_90, @acc_902=@acc_90, @acc_862=@acc_962 ------------------------------------------------------------- */ declare @sum_bal money, @qty_sum decimal(24,10) ------------------------------------------------------- select @sum_bal=isnull(sum(isnull(ol1.sum_bal,0)),0), @qty_sum=isnull(sum(isnull(ol1.qty_sum,0)),0) from t_oper_list ol1, t_oper_list ol2 where ol1.partner2plan_id = @plan2partner and ol2.partner2plan_id = @plan2partner and ol1.op_date > @start_date and ol2.op_date > @start_date and ol1.op_date < dateadd(day, 1, @srez_date) and ol2.op_date < dateadd(day, 1, @srez_date) and ol1.acc_id=@acc_901 and ol1.deb_or_cred=-1 and ol2.acc_id in (@acc_551,@acc_7610,@acc_7611,@acc_7612,@acc_7614,@acc_7615,@acc_7616, @acc_7617,@acc_7618,@acc_762,@acc_763,@acc_7641,@acc_7642,@acc_7651, @acc_7652,@acc_7653,@acc_7654,@acc_7655,@acc_766,@acc_767,@acc_768,@acc_769) and ol2.deb_or_cred=1 and ol1.head_id=ol2.head_id and ol1.id!=ol2.id group by ol1.acc_id insert into #report(row_code, row_name, row_sum,row_qty) select 'STOCK_SALE_PROCEEDS', 'Выручка от продажи ценных бумаг', isnull(@sum_bal,0),isnull(@qty_sum,0) --------------------------------------------------------- select @sum_bal=0, @qty_sum=0 ------------------------------------------------------- select @sum_bal=isnull(sum(isnull(ol1.sum_bal,0)),0), @qty_sum=isnull(sum(isnull(ol1.qty_sum,0)),0) from t_oper_list ol1, t_oper_list ol2 where ol1.partner2plan_id = @plan2partner and ol2.partner2plan_id = @plan2partner and ol1.op_date > @start_date and ol2.op_date > @start_date and ol1.op_date < dateadd(day, 1, @srez_date) and ol2.op_date < dateadd(day, 1, @srez_date) and ol1.acc_id=@acc_902 and ol1.deb_or_cred=1 and ol2.acc_id in (@acc_581,@acc_7612,@acc_551) and ol2.deb_or_cred=-1 and ol1.head_id=ol2.head_id and ol1.id!=ol2.id group by ol1.acc_id insert into #report(row_code, row_name, row_sum,row_qty) select 'STOCK_SALE_EXPENSES', 'Расходы, связанные с продажей ценных бумаг', isnull(@sum_bal,0),isnull(@qty_sum,0) --------------------------------------------------------- select @sum_bal=0, @qty_sum=0 --------------------------------------------------------- select @sum_bal=isnull(sum(isnull(ol1.sum_bal,0)),0), @qty_sum=isnull(sum(isnull(ol1.qty_sum,0)),0) from t_oper_list ol1, t_oper_list ol2, t_operations op where ol1.partner2plan_id = @plan2partner and ol2.partner2plan_id = @plan2partner and ol1.op_date > @start_date and ol2.op_date > @start_date and ol1.op_date < dateadd(day, 1, @srez_date) and ol2.op_date < dateadd(day, 1, @srez_date) and ol1.acc_id=@acc_901 and ol1.deb_or_cred=-1 and ol2.acc_id=@acc_7613 and ol2.deb_or_cred=1 and ol1.head_id=ol2.head_id and op.id=ol1.head_id and exists (select 1 from t_operations op1, t_oper_list ol902, t_oper_list ol011 where op1.item_id=op.item_id and ol902.head_id=op1.id and ol011.head_id=op1.id and ol011.partner2plan_id = @plan2partner and ol902.partner2plan_id = @plan2partner and ol011.op_date > @start_date and ol902.op_date > @start_date and ol011.op_date < dateadd(day, 1, @srez_date) and ol902.op_date < dateadd(day, 1, @srez_date) and ol011.acc_id=@acc_011 and ol011.deb_or_cred=-1 and ol902.acc_id=@acc_902 and ol902.deb_or_cred=1 and ol011.id!=ol902.id) and ol1.id!=ol2.id group by ol1.acc_id insert into #report(row_code, row_name, row_sum,row_qty) select 'REALTY_SALE_PROCEEDS', 'Выручка от продажи недвижимого имущества или передачи имущественных прав на недвижимое имущество', isnull(@sum_bal,0),isnull(@qty_sum,0) --------------------------------------------------------- select @sum_bal=0, @qty_sum=0 --------------------------------------------------------- select @sum_bal=isnull(sum(isnull(ol1.sum_bal,0)),0), @qty_sum=isnull(sum(isnull(ol1.qty_sum,0)),0) from t_oper_list ol1, t_oper_list ol2, t_operations op where ol1.partner2plan_id = @plan2partner and ol2.partner2plan_id = @plan2partner and ol1.op_date > @start_date and ol2.op_date > @start_date and ol1.op_date < dateadd(day, 1, @srez_date) and ol2.op_date < dateadd(day, 1, @srez_date) and ol1.acc_id=@acc_902 and ol1.deb_or_cred=1 and ol2.acc_id=@acc_7615 and ol2.deb_or_cred=-1 and ol1.head_id=ol2.head_id and op.id=ol1.head_id and exists (select 1 from t_operations op1, t_oper_list ol902, t_oper_list ol011 where op1.item_id=op.item_id and ol902.head_id=op1.id and ol011.head_id=op1.id and ol011.partner2plan_id = @plan2partner and ol902.partner2plan_id = @plan2partner and ol011.op_date > @start_date and ol902.op_date > @start_date and ol011.op_date < dateadd(day, 1, @srez_date) and ol902.op_date < dateadd(day, 1, @srez_date) and ol011.acc_id=@acc_011 and ol011.deb_or_cred=-1 and ol902.acc_id=@acc_902 and ol902.deb_or_cred=1 and ol011.id!=ol902.id) and ol1.id!=ol2.id group by ol1.acc_id select @sum_bal=@sum_bal+isnull(sum(isnull(ol1.sum_bal,0)),0), @qty_sum=@qty_sum+isnull(sum(isnull(ol1.qty_sum,0)),0) from t_oper_list ol1, t_oper_list ol2 where ol1.partner2plan_id = @plan2partner and ol2.partner2plan_id = @plan2partner and ol1.op_date > @start_date and ol2.op_date > @start_date and ol1.op_date < dateadd(day, 1, @srez_date) and ol2.op_date < dateadd(day, 1, @srez_date) and ol1.acc_id=@acc_902 and ol1.deb_or_cred=1 and ol2.acc_id=@acc_011 and ol2.deb_or_cred=-1 and ol1.head_id=ol2.head_id and ol1.id!=ol2.id group by ol1.acc_id insert into #report(row_code, row_name, row_sum,row_qty) select 'REALTY_SALE_EXPENSES', 'Расходы, связанные с продажей недвижимого имущества или передачей имущественных прав на недвижимое имущество', @sum_bal,@qty_sum --------------------------------------------------------- select @sum_bal=0, @qty_sum=0 --------------------------------------------------------- select @sum_bal=isnull(sum(isnull(ol1.sum_bal,0)),0), @qty_sum=isnull(sum(isnull(ol1.qty_sum,0)),0) from t_oper_list ol1, t_oper_list ol2, t_operations op where ol1.partner2plan_id = @plan2partner and ol2.partner2plan_id = @plan2partner and ol1.op_date > @start_date and ol2.op_date > @start_date and ol1.op_date < dateadd(day, 1, @srez_date) and ol2.op_date < dateadd(day, 1, @srez_date) and ol1.acc_id=@acc_901 and ol1.deb_or_cred=-1 and ol2.acc_id=@acc_7613 and ol2.deb_or_cred=1 and ol1.head_id=ol2.head_id and op.id=ol1.head_id and exists (select 1 from t_operations op1, t_oper_list ol902, t_oper_list ol583 where op1.item_id=op.item_id and ol902.head_id=op1.id and ol583.head_id=op1.id and ol583.partner2plan_id = @plan2partner and ol902.partner2plan_id = @plan2partner and ol583.op_date > @start_date and ol902.op_date > @start_date and ol583.op_date < dateadd(day, 1, @srez_date) and ol902.op_date < dateadd(day, 1, @srez_date) and ol583.acc_id=@acc_583 and ol583.deb_or_cred=-1 and ol902.acc_id=@acc_902 and ol902.deb_or_cred=1 and ol583.id!=ol902.id) and ol1.id!=ol2.id group by ol1.acc_id insert into #report(row_code, row_name, row_sum,row_qty) select 'OTHER_SALE_PROCEEDS', 'Выручка от продажи иного имущества', isnull(@sum_bal,0),isnull(@qty_sum,0) --------------------------------------------------------- select @sum_bal=0, @qty_sum=0 --------------------------------------------------------- select @sum_bal=isnull(sum(isnull(ol1.sum_bal,0)),0), @qty_sum=isnull(sum(isnull(ol1.qty_sum,0)),0) from t_oper_list ol1, t_oper_list ol2, t_operations op where ol1.partner2plan_id = @plan2partner and ol2.partner2plan_id = @plan2partner and ol1.op_date > @start_date and ol2.op_date > @start_date and ol1.op_date < dateadd(day, 1, @srez_date) and ol2.op_date < dateadd(day, 1, @srez_date) and ol1.acc_id=@acc_902 and ol1.deb_or_cred=1 and ol2.acc_id=@acc_7615 and ol2.deb_or_cred=-1 and ol1.head_id=ol2.head_id and op.id=ol1.head_id and exists (select 1 from t_operations op1, t_oper_list ol902, t_oper_list ol583 where op1.item_id=op.item_id and ol902.head_id=op1.id and ol583.head_id=op1.id and ol583.partner2plan_id = @plan2partner and ol902.partner2plan_id = @plan2partner and ol583.op_date > @start_date and ol902.op_date > @start_date and ol583.op_date < dateadd(day, 1, @srez_date) and ol902.op_date < dateadd(day, 1, @srez_date) and ol583.acc_id=@acc_583 and ol583.deb_or_cred=-1 and ol902.acc_id=@acc_902 and ol902.deb_or_cred=1 and ol583.id!=ol902.id) and ol1.id!=ol2.id group by ol1.acc_id select @sum_bal=@sum_bal+isnull(sum(isnull(ol1.sum_bal,0)),0), @qty_sum=@qty_sum+isnull(sum(isnull(ol1.qty_sum,0)),0) from t_oper_list ol1, t_oper_list ol2 where ol1.partner2plan_id = @plan2partner and ol2.partner2plan_id = @plan2partner and ol1.op_date > @start_date and ol2.op_date > @start_date and ol1.op_date < dateadd(day, 1, @srez_date) and ol2.op_date < dateadd(day, 1, @srez_date) and ol1.acc_id=@acc_902 and ol1.deb_or_cred=1 and ol2.acc_id=@acc_583 and ol2.deb_or_cred=-1 and ol1.head_id=ol2.head_id and ol1.id!=ol2.id group by ol1.acc_id insert into #report(row_code, row_name, row_sum,row_qty) select 'OTHER_SALE_EXPENSES', 'Расходы, связанные с продажей иного имущества', @sum_bal,@qty_sum --------------------------------------------------------- --------------------------------------------------------- select @sum_bal=0, @qty_sum=0 --------------------------------------------------------- declare @subc_type_id numeric select @subc_type_id=.SUBCTYPE_FROM_CODE('pifdocs') select @sum_bal=isnull(sum(isnull(ol.sum_bal,0)),0), @qty_sum=isnull(sum(isnull(ol.qty_sum,0)),0) from t_oper_list ol, t_operations o where o.partner2plan_id=@plan2partner and ol.head_id=o.id and ol.acc_id in (@acc_861,@acc_865) and (o.op_date=@start_date) and ol.deb_or_cred=1 and exists(select 1 from t_oper_list ol2, t_oper_subconto os, tp_pif_queries d where ol2.head_id=o.id and ol2.acc_id = @acc_7642 and ol2.deb_or_cred=-1 and os.id=ol2.id and os.subconto_type_id=@subc_type_id and os.item_id=d.id and isnull(d.type_queries,0)=4) select @sum_bal=@sum_bal-isnull(sum(isnull(ol.sum_bal,0)),0), @qty_sum=@qty_sum-isnull(sum(isnull(ol.qty_sum,0)),0) from t_oper_list ol, t_operations o where o.partner2plan_id=@plan2partner and ol.head_id=o.id and ol.acc_id=@acc_865 and (o.op_date=@start_date) and ol.deb_or_cred=-1 and exists(select 1 from t_oper_list ol2, t_oper_subconto os, tp_pif_queries d where ol2.head_id=o.id and ol2.acc_id = @acc_7642 and ol2.deb_or_cred=1 and os.id=ol2.id and os.subconto_type_id=@subc_type_id and os.item_id=d.id and isnull(d.type_queries,0)=4) select @qty_sum=.PAYS_QTY_CALC(@qty_sum,@fond_id) insert into #report(row_code, row_name, row_sum, row_qty) select 'PAYS_EXCHANGE', 'Погашение инвестиционных паев по обмену', @sum_bal, @qty_sum --------------------------------------------------------- select @sum_bal=0, @qty_sum=0 --------------------------------------------------------- select @sum_bal=isnull(sum(isnull(ol.sum_bal,0)),0), @qty_sum=isnull(sum(isnull(ol.qty_sum,0)),0) from t_oper_list ol, t_operations o where o.partner2plan_id=@plan2partner and ol.head_id=o.id and ol.acc_id in (@acc_861,@acc_865) and (o.op_date=@start_date) and ol.deb_or_cred=-1 and exists(select 1 from t_oper_list ol2, t_oper_subconto os, tp_pif_queries d, t_paydocs where ol2.head_id=o.id and ol2.acc_id = @acc_7641 and ol2.deb_or_cred=1 and os.id=ol2.id and os.item_id=t_paydocs.id and t_paydocs.pif_pay_id = d.id and isnull(d.type_queries,0)=3) select @qty_sum=.PAYS_QTY_CALC(@qty_sum,@fond_id) insert into #report(row_code, row_name, row_sum, row_qty) select 'PAYS_EXCHANGE_OUT', 'Выдача инвестиционных паев по обмену', @sum_bal, @qty_sum --------------------------------------------------------- select @sum_bal=0, @qty_sum=0 --------------------------------------------------------- select @sum_bal=isnull(sum(isnull(ol1.sum_bal,0)),0), @qty_sum=isnull(sum(isnull(ol1.qty_sum,0)),0) from t_oper_list ol1, t_oper_list ol2 where ol1.partner2plan_id = @plan2partner and ol2.partner2plan_id = @plan2partner and ol1.op_date >= @start_date and ol2.op_date >= @start_date and ol1.op_date < dateadd(day, 1, @srez_date) and ol2.op_date < dateadd(day, 1, @srez_date) and ol1.acc_id=@acc_861 and ol1.deb_or_cred=1 and ol2.acc_id=@acc_861 and ol2.deb_or_cred=-1 and ol1.head_id=ol2.head_id and ol1.id!=ol2.id group by ol1.acc_id insert into #report(row_code, row_name, row_sum, row_qty) select 'PAYS_MOVES_SUM', 'Оборот по передаче паев', isnull(@sum_bal,0), isnull((.PAYS_QTY_CALC(@qty_sum,@fond_id)),0) --------------------------------------------------------- select @sum_bal=0, @qty_sum=0 --------------------------------------------------------- insert into #report(row_code, row_name, row_sum, row_qty) select 'PAYMENT_PROFIT_MANAGEMENT_ZPIF', 'Выплата дохода от ДУ ЗПИФ', @sum_bal, @qty_sum --------------------------------------------------------- ---Среднегодовая СЧА------------ declare @scha_aver money, @scha_count int, @scha_sums money if @start_date is not null begin select @scha_count=count(scha_sum), @scha_sums=sum(isnull(scha_sum,0)) from tp_pif_price_change where fond_id=@fond_id and change_date>=@start_date and change_date @start_date and ol2.op_date > @start_date and ol1.op_date < dateadd(day, 1, @srez_date) and ol2.op_date < dateadd(day, 1, @srez_date) and ol2.acc_id=@acc_862 and ol2.deb_or_cred=1 and ol1.acc_id=@acc_768 and ol1.deb_or_cred=-1 and ol1.head_id=ol2.head_id and ol1.id!=ol2.id group by ol1.acc_id insert into #report(row_code, row_name, row_sum,row_qty) select 'CTRL_EXPENSES', 'Расходы, связанные с доверительным управлением ПИФ', isnull(@sum_bal,0),isnull(@qty_sum,0) --------------------------------------------------------- ------------Пункты для ввода информации, не собираемой в срезе!!! --отчет о вознаграждении, строки 021-... insert into #report(row_code, row_name, row_sum,row_qty) select 'CTRL_EXPENSES_ACC', 'Ведение расчетного счета', 0,0 insert into #report(row_code, row_name, row_sum,row_qty) select 'CTRL_EXPENSES_PUBL', 'Публикации', 0,0 insert into #report(row_code, row_name, row_sum,row_qty) select 'CTRL_EXPENSES_COMPENS', 'Возмещение расходов', 0,0 --------------------------------------------------------- delete t_items from tp_pif_srez_add_info, t_types where t_items.id = tp_pif_srez_add_info.id and tp_pif_srez_add_info.srez_id = @id and t_types.id=t_items.type_id and upper(t_types.type_code)='PIF_SREZ_ADD_INFO' delete tp_pif_srez_add_info where tp_pif_srez_add_info.srez_id = @id and not exists(select 1 from t_items where id=tp_pif_srez_add_info.id) declare @row_code9_1 varchar(50), @row_name9_1 varchar(255), @row_sum9_1 money, @row_qty9_1 decimal(18,8) declare info_cur cursor for select row_code,row_name,row_sum,row_qty from #report open info_cur fetch info_cur into @row_code9_1,@row_name9_1,@row_sum9_1,@row_qty9_1 while .CURSOR_STATE=0 begin .TYPE_INIT('PIF_SREZ_ADD_INFO',9) .TYPE_ASSIGN(srez_id,@id,9) .TYPE_INSERT('PIF_SREZ_ADD_INFO','CRT',9) fetch info_cur into @row_code9_1,@row_name9_1,@row_sum9_1,@row_qty9_1 end close info_cur .DEALLOCATE info_cur -- срез с нач.остатками ------------------------------------------------------------------------------------- declare @start_id numeric if @srez_date_b is not null begin select @start_id=(select max(s.id) from tp_pif_srez s where .ITEMS_EXISTS(s.id) and s.srez_date>=@srez_date_b and s.srez_date<=@srez_date and s.fond_id=@fond_id and .GET_CLASS_VALUE_CODE_FOR_ITEM(s.id,'PIF_SREZ_TYPE','DEFAULT')='START') if @start_id is not null update tp_pif_srez_add_info set row_sum=isnull(tp_pif_srez_add_info.row_sum,0)+isnull(p.row_sum,0), row_qty=isnull(tp_pif_srez_add_info.row_qty,0)+isnull(p.row_qty,0) from tp_pif_srez_add_info, tp_pif_srez_add_info p where tp_pif_srez_add_info.srez_id=@id and p.srez_id=@start_id and tp_pif_srez_add_info.row_code=p.row_code and .ITEMS_EXISTS(tp_pif_srez_add_info.id) and .ITEMS_EXISTS(p.id) and tp_pif_srez_add_info.row_code in ( 'STOCK_SALE_PROCEEDS', 'STOCK_SALE_EXPENSES', 'CTRL_EXPENSES', 'PAYS_EXCHANGE') end -------------------------------------------------------------------------------------------------------- if @startsrez_id is null update tp_pif_srez_add_info set row_sum=0, row_qty=0 where srez_id=@id commit tran drop table #report .TRANSACTION_RESTORE